OK, by the way I see it an alternative structure for SymPy's pattern
matcher could be to define .match( ) in Basic only and cleverly use method
inheritance. That is:
- express associativity through a static field (e.g. is_Associative)
- same if the type is an identity when given only one parameter (e.g.
is_one_param_identity)
- I would express commutativity as a method returning a generator of
permutations
- to match inverses use again a static field in the class (e.g.
inverse_matcher)
- Pow requires a special case for its exponent-matching.
These 5 properties should be the extensions over a structural matcher
introduced by SymPy's matcher.
In examples:
class Basic(object):
...
is_Associative = False # Basic(1, 2) != Basic(1, Basic(2))
is_one_param_identity = False # Basic(1) != 1
def get_permutation_iter(self):
def f():
yield self.args
return f
inverse_matcher = None
class Mul(Expr):
...
is_Associative = True
is_one_param_identity = True # Mul(x) == x
def get_permutation_iter(self):
def f():
... iter through all possible permutations such that
... the non-commutative parts do not commute
return f
inverse_match = "x -> Pow(x, -1)"
In this way, the information about how a specific type behaves under
pattern matching can be easily customized. The generator of allowed
permutations would thus be useful in cases where the commutation properties
are complicated, for example when they are specified by a generic element
of the symmetric group for the object instance.
Anyways, I would consider this task as low priority. Better first
concentrate on import the RUBI ruleset into SymPy.
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/360c7f93-3172-4454-992d-5116c4f2c5c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.