Module Expr Str ImportFrom alias alias ImportFrom alias ImportFrom alias ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return BoolOpAnd CompareEq Call NameLoad NameLoad Call NameLoad NameLoad CompareEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr CompareEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return Call NameLoad TupleLoad Call NameLoad NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str TupleLoad Call NameLoad AttributeLoad NameLoad attr Call AttributeLoad Str attr Call NameLoad NameLoad AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return BoolOpAnd CompareEq Call NameLoad NameLoad Call NameLoad NameLoad CompareEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return Call NameLoad TupleLoad Call NameLoad NameLoad AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str Call NameLoad AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases NameLoad body Expr Str FunctionDef arguments args NameParam NameParam NameParam defaults body Assign AttributeStore NameLoad attr NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Return BoolOpAnd CompareEq Call NameLoad NameLoad Call NameLoad NameLoad CompareEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr CompareEq AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return Call NameLoad TupleLoad Call NameLoad NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Return BinOpMod Str Call NameLoad AttributeLoad NameLoad attr decorator_list decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults NameLoad kwarg body Expr Str Assign NameStore BoolOpOr NameLoad Dict If CompareEq NameLoad NameLoad body Expr Yield NameLoad orelse If Call NameLoad NameLoad TupleLoad NameLoad NameLoad body For NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad body Expr Yield NameLoad orelse If Call NameLoad NameLoad TupleLoad NameLoad NameLoad body For NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad body Expr Yield NameLoad orelse If BoolOpAnd Call NameLoad NameLoad NameLoad Call NameLoad NameLoad NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Str Lambda arguments args NameParam defaults NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str Lambda arguments args NameParam defaults NameLoad For NameStore Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad body If BoolOpAnd Call NameLoad NameLoad Call NameLoad NameLoad body Assign TupleStore NameStore NameStore IfExp CompareLt Call NameLoad AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr TupleLoad NameLoad NameLoad TupleLoad NameLoad NameLoad If BoolOpAnd Call NameLoad NameLoad Call NameLoad NameLoad body Assign NameStore Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str orelse Assign NameStore Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str For TupleStore NameStore NameStore NameLoad body Assign NameStore ListComp Call NameLoad Call NameLoad AttributeLoad NameLoad attr NameLoad comprehension NameStore NameLoad Assign NameStore ListComp Call NameLoad Call NameLoad AttributeLoad NameLoad attr NameLoad comprehension NameStore NameLoad For NameStore Call NameLoad NameLoad NameLoad NameLoad NameLoad body Expr Yield NameLoad orelse If CompareEq Call NameLoad AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr body For NameStore Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad body Expr Yield NameLoad orelse If BoolOpAnd Call NameLoad NameLoad Call NameLoad NameLoad CompareEq Call NameLoad NameLoad Call NameLoad NameLoad body If CompareEq Call NameLoad NameLoad Num body Expr Yield NameLoad orelse For NameStore Call NameLoad SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num NameLoad NameLoad body For NameStore Call NameLoad SubscriptLoad NameLoad Slice Num SubscriptLoad NameLoad Slice Num NameLoad NameLoad body Expr Yield NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults kwarg body If CompareIn NameLoad NameLoad body For NameStore Call NameLoad SubscriptLoad NameLoad Index NameLoad NameLoad NameLoad NameLoad body Expr Yield NameLoad orelse If Call NameLoad NameLoad NameLoad body Pass orelse If BoolOpAnd Call NameLoad NameLoad NameLoad Call AttributeLoad NameLoad attr NameLoad body Expr Yield Call NameLoad NameLoad NameLoad NameLoad orelse If Call NameLoad NameLoad NameLoad body Expr Yield Call NameLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If CompareEq NameLoad NameLoad body Return NameLoad orelse If Call NameLoad NameLoad NameLoad body Return Call NameLoad NameLoad AttributeLoad NameLoad attr orelse If Call NameLoad NameLoad body If Call NameLoad GeneratorExp Call NameLoad NameLoad NameLoad comprehension NameStore NameLoad body Return NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Assign SubscriptStore NameLoad Index NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return CompareIn Call NameLoad NameLoad TupleLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam defaults body If BoolOpAnd Call NameLoad NameLoad NameLoad CompareEq Call NameLoad AttributeLoad NameLoad attr Num body Return SubscriptLoad AttributeLoad NameLoad attr Index Num orelse Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str If CompareEq NameLoad Str body Assign NameStore Num If CompareEq NameLoad Str body Assign NameStore NameLoad Assign TupleStore NameStore NameStore IfExp CompareLt Call NameLoad NameLoad Call NameLoad NameLoad TupleLoad NameLoad NameLoad TupleLoad NameLoad NameLoad For NameStore Call NameLoad Call NameLoad Call NameLoad Call NameLoad NameLoad Call NameLoad NameLoad keyword NameLoad body If CompareEq NameLoad NameLoad body Expr Yield TupleLoad Call NameLoad GeneratorExp TupleLoad NameLoad comprehension NameStore NameLoad Call NameLoad NameLoad NameLoad orelse Expr Yield TupleLoad Call NameLoad NameLoad NameLoad Call NameLoad GeneratorExp TupleLoad NameLoad comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call Call NameLoad NameLoad ListComp Call NameLoad NameLoad NameLoad comprehension NameStore NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call Call NameLoad NameLoad ListComp SubscriptLoad NameLoad Index NameLoad comprehension NameStore NameLoad decorator_list
N/A N/A  Generic Unification algorithm for expression trees with lists of children

This implementation is a direct translation of

Artificial Intelligence: A Modern Approach by Stuart Russel and Peter Norvig
Second edition, section 9.2, page 276

It is modified in the following ways:

1.  We allow associative and commutative Compound expressions. This results in
    combinatorial blowup.
2.  We explore the tree lazily.
3.  We provide generic interfaces to symbolic algebra libraries in Python.

A more traditional version can be found here
http://aima.cs.berkeley.edu/python/logic.html
 __future__ print_function division sympy.utilities.iterables kbins sympy.core.compatibility range Compound N/A object N/A N/A  A little class to represent an interior node in the tree

    This is analagous to SymPy.Basic for non-Atoms
     __init__ N/A N/A self op args N/A N/A N/A N/A self op op N/A N/A self args args N/A __eq__ N/A N/A self other N/A N/A N/A N/A N/A N/A type self N/A type other N/A N/A self op N/A other op N/A N/A self args N/A other args N/A __hash__ N/A N/A self N/A N/A N/A N/A hash N/A N/A type self N/A self op N/A self args N/A __str__ N/A N/A self N/A N/A N/A N/A %s[%s] N/A N/A str N/A self op N/A N/A ,  join N/A map str N/A self args N/A N/A Variable N/A object N/A N/A  A Wild token  __init__ N/A N/A self arg N/A N/A N/A N/A self arg arg N/A __eq__ N/A N/A self other N/A N/A N/A N/A N/A N/A type self N/A type other N/A N/A self arg N/A other arg N/A __hash__ N/A N/A self N/A N/A N/A N/A hash N/A N/A type self N/A self arg N/A __str__ N/A N/A self N/A N/A N/A N/A Variable(%s) N/A str N/A self arg N/A N/A CondVariable N/A object N/A N/A  A wild token that matches conditionally

    arg   - a wild token
    valid - an additional constraining function on a match
     __init__ N/A N/A self arg valid N/A N/A N/A N/A self arg arg N/A N/A self valid valid N/A __eq__ N/A N/A self other N/A N/A N/A N/A N/A N/A type self N/A type other N/A N/A self arg N/A other arg N/A N/A self valid N/A other valid N/A __hash__ N/A N/A self N/A N/A N/A N/A hash N/A N/A type self N/A self arg N/A self valid N/A __str__ N/A N/A self N/A N/A N/A N/A CondVariable(%s) N/A str N/A self arg N/A N/A unify N/A N/A x y s N/A None fns N/A N/A  Unify two expressions

    inputs:
        x, y - expression trees containing leaves, Compounds and Variables
        s    - a mapping of variables to subtrees
    outputs:
        lazy sequence of mappings {Variable: subtree}

    Examples
    ========

    >>> from sympy.unify.core import unify, Compound, Variable
    >>> expr    = Compound("Add", ("x", "y"))
    >>> pattern = Compound("Add", ("x", Variable("a")))
    >>> next(unify(expr, pattern, {}))
    {Variable(a): 'y'}
     N/A s N/A s N/A N/A N/A x y N/A N/A N/A s N/A N/A N/A isinstance x N/A Variable CondVariable N/A N/A match N/A unify_var x y s fns N/A N/A N/A match N/A N/A N/A isinstance y N/A Variable CondVariable N/A N/A match N/A unify_var y x s fns N/A N/A N/A match N/A N/A N/A N/A isinstance x Compound N/A isinstance y Compound N/A N/A is_commutative N/A N/A fns get is_commutative N/A N/A N/A x N/A False N/A is_associative N/A N/A fns get is_associative N/A N/A N/A x N/A False N/A sop N/A unify N/A x op N/A y op s fns N/A N/A N/A N/A is_associative x N/A is_associative y N/A N/A N/A a b N/A N/A N/A len N/A x args N/A len N/A y args N/A x y N/A y x N/A N/A N/A is_commutative x N/A is_commutative y N/A N/A combs N/A allcombinations N/A a args N/A b args commutative N/A N/A combs N/A allcombinations N/A a args N/A b args associative N/A N/A aaargs bbargs combs N/A N/A aa N/A N/A unpack N/A Compound N/A a op arg N/A arg aaargs N/A bb N/A N/A unpack N/A Compound N/A b op arg N/A arg bbargs N/A match N/A unify aa bb sop fns N/A N/A N/A match N/A N/A N/A N/A len N/A x args N/A len N/A y args N/A N/A match N/A unify N/A x args N/A y args sop fns N/A N/A N/A match N/A N/A N/A N/A is_args x N/A is_args y N/A N/A len x N/A len y N/A N/A N/A N/A len x 0 N/A N/A N/A s N/A N/A shead N/A unify N/A x N/A 0 N/A y N/A 0 s fns N/A N/A match N/A unify N/A x N/A 1 N/A y N/A 1 shead fns N/A N/A N/A match N/A unify_var N/A N/A var x s N/A fns N/A N/A N/A var s N/A N/A match N/A unify N/A s N/A var x s fns N/A N/A N/A match N/A N/A N/A occur_check var x N/A N/A N/A N/A N/A N/A isinstance var CondVariable N/A N/A var valid x N/A N/A N/A N/A assoc s var x N/A N/A N/A isinstance var Variable N/A N/A N/A N/A assoc s var x N/A occur_check N/A N/A var x N/A N/A N/A  var occurs in subtree owned by x?  N/A N/A var x N/A N/A True N/A N/A N/A isinstance x Compound N/A N/A N/A occur_check var N/A x args N/A N/A N/A is_args x N/A N/A N/A any N/A N/A occur_check var xi N/A xi x N/A N/A True N/A False N/A assoc N/A N/A d key val N/A N/A N/A  Return copy of d with key associated to val  N/A d N/A N/A d copy N/A N/A d N/A key val N/A d N/A is_args N/A N/A x N/A N/A N/A  Is x a traditional iterable?  N/A N/A N/A type x N/A tuple list set N/A unpack N/A N/A x N/A N/A N/A N/A N/A isinstance x Compound N/A N/A len N/A x args 1 N/A N/A N/A N/A x args N/A 0 N/A N/A x N/A allcombinations N/A N/A A B ordered N/A N/A N/A 
    Restructure A and B to have the same number of elements

    ordered must be either 'commutative' or 'associative'

    A and B can be rearranged so that the larger of the two lists is
    reorganized into smaller sublists.

    >>> from sympy.unify.core import allcombinations
    >>> for x in allcombinations((1, 2, 3), (5, 6), 'associative'): print(x)
    (((1,), (2, 3)), ((5,), (6,)))
    (((1, 2), (3,)), ((5,), (6,)))

    >>> for x in allcombinations((1, 2, 3), (5, 6), 'commutative'): print(x)
        (((1,), (2, 3)), ((5,), (6,)))
        (((1, 2), (3,)), ((5,), (6,)))
        (((1,), (3, 2)), ((5,), (6,)))
        (((1, 3), (2,)), ((5,), (6,)))
        (((2,), (1, 3)), ((5,), (6,)))
        (((2, 1), (3,)), ((5,), (6,)))
        (((2,), (3, 1)), ((5,), (6,)))
        (((2, 3), (1,)), ((5,), (6,)))
        (((3,), (1, 2)), ((5,), (6,)))
        (((3, 1), (2,)), ((5,), (6,)))
        (((3,), (2, 1)), ((5,), (6,)))
        (((3, 2), (1,)), ((5,), (6,)))
     N/A N/A ordered commutative N/A N/A ordered 11 N/A N/A ordered associative N/A N/A ordered None N/A N/A sm bg N/A N/A N/A len A N/A len B N/A A B N/A B A N/A part N/A kbins N/A list N/A range N/A len bg N/A len sm ordered ordered N/A N/A N/A bg B N/A N/A N/A N/A N/A tuple N/A N/A a N/A a A N/A partition B part N/A N/A N/A N/A N/A partition A part N/A tuple N/A N/A b N/A b B N/A partition N/A N/A it part N/A N/A N/A  Partition a tuple/list into pieces defined by indices

    >>> from sympy.unify.core import partition
    >>> partition((10, 20, 30, 40), [[0, 1, 2], [3]])
    ((10, 20, 30), (40,))
     N/A N/A N/A type it N/A N/A index it ind N/A ind part N/A index N/A N/A it ind N/A N/A N/A  Fancy indexing into an indexable iterable (tuple, list)

    >>> from sympy.unify.core import index
    >>> index([10, 20, 30], (1, 2, 0))
    [20, 30, 10]
     N/A N/A N/A type it N/A N/A it N/A i N/A i ind N/A