Comments (3)
Here is my Constraint
class (cons()
):
from matchpy import Constraint, substitute
from sympy import sympify
class cons(Constraint):
def __init__(self, expr, vars):
self.expr = expr
self.vars = frozenset(v.name for v in vars)
def __call__(self, substitution):
sub = substitute(self.expr, substitution)
try:
return sympify(str(sub))
except:
print(('Unable to sympify: {}').format(sub))
return False
@property
def variables(self):
return self.vars
def with_renamed_vars(self, renaming):
copy = cons(self.expr, [])
copy.vars = frozenset(renaming.get(v, v) for v in self.vars)
return copy
def __eq__(self, other):
return isinstance(other, cons) and other.vars == self.vars and other.expr == self.expr
def __hash__(self):
return hash((self.vars, self.expr))
I figured out that self.vars
are getting changed in with_renamed_vars
from frozenset({'m', 'x'})
to frozenset({'i1', 'i2'})
and stays the same when __call__
is called.
from matchpy.
You will have to rename the variables in the expression as well:
def with_renamed_vars(self, renaming):
new_expr = self.expr.with_renamed_vars(renaming)
new_vars = [renaming.get(v, v) for v in self.vars]
return cons(new_expr, new_vars)
Unfortunately, this will only work if the expression consists of Expression
instances, i.e. no int
s etc. I want to get rid of the requirement for renaming. I hope I can get to that next week, but I can't promise it.
from matchpy.
Thanks!
from matchpy.
Related Issues (20)
- Wildcard that matches multiple symbols HOT 1
- Create `new` class method on Symbol HOT 1
- ManyToOneMatcher: Position of constraints logic HOT 3
- GPL'd dependency: hopcroftkarp library HOT 6
- Usage of type unions HOT 1
- [Feature] Visualization of Expressions with Graphviz
- ANN: MatchPyCpp port to C++ HOT 7
- New release? HOT 5
- Remove dependency on pkg_resources/setuptools HOT 1
- Inconsistent output of match_anywhere HOT 4
- Improve checking correctness of input
- Match arbitrary function HOT 4
- One-to-one matching: symbols with variable_name do not work in commutative functions HOT 2
- substitute not working with SymPy HOT 11
- Optional wildcards to match the identity element of the current node HOT 7
- FreeQ equivalent in MatchPy? HOT 1
- New MatchPy version? HOT 5
- Expression matching with patterns without wildcards HOT 4
- Overridable node visitors instead of typed-nodes in expression trees HOT 2
- Project fails on test cases
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matchpy.