Comments (9)
I am not sure why you would want to have a constant wildcard. The whole point of wildcards is that they do match anything, not just a constant value. You can use any Symbol
or ConstantSymbol
in a pattern as well. Your code works fine for me, too. A traceback or some code of what you are trying to use the ConstantWild for would be helpful. If you want a wildcard, that can only match constants, you can use the SymbolWildcard
class or just a = Wildcard.symbol('a', ConstantSymbol)
.
from matchpy.
When I have a pattern(Which uses ConstantSymbol
):
And(FreeQ(m_, x_), NonzeroQ(Add(ConstantSymbol(1), m_)))
and I want to substitute variables. I am receiving errors:
File "/users/parsoyaarihant/sympy/sympy/rubi/tests/test_rubi.py", line 8, in test_rubi_integrate
print(rubi_integrate(expr, x))
File "/Users/parsoyaarihant/sympy/sympy/rubi/rubi.py", line 17, in rubi_integrate
rubi = rubi_object()
File "/Users/parsoyaarihant/sympy/sympy/rubi/patterns.py", line 40, in rubi_object
rubi.add(rule2)
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/matching/many_to_one.py", line 730, in add
self.matcher.add(rule.pattern, rule.replacement)
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/matching/many_to_one.py", line 330, in add
self._internal_add(pattern, label, renaming)
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/matching/many_to_one.py", line 346, in _internal_add
renamed_constraints = [c.with_renamed_vars(renaming) for c in pattern.local_constraints]
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/matching/many_to_one.py", line 346, in <listcomp>
renamed_constraints = [c.with_renamed_vars(renaming) for c in pattern.local_constraints]
File "/Users/parsoyaarihant/sympy/sympy/rubi/constraint.py", line 22, in with_renamed_vars
copy = cons(self.expr.with_renamed_vars(renaming), [])
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/expressions/expressions.py", line 592, in with_renamed_vars
variable_name=renaming.get(self.variable_name, self.variable_name)
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/expressions/expressions.py", line 591, in <genexpr>
*(o.with_renamed_vars(renaming) for o in self.operands),
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/expressions/expressions.py", line 592, in with_renamed_vars
variable_name=renaming.get(self.variable_name, self.variable_name)
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/expressions/expressions.py", line 591, in <genexpr>
*(o.with_renamed_vars(renaming) for o in self.operands),
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/expressions/expressions.py", line 592, in with_renamed_vars
variable_name=renaming.get(self.variable_name, self.variable_name)
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/expressions/expressions.py", line 591, in <genexpr>
*(o.with_renamed_vars(renaming) for o in self.operands),
File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3.1-py3.6.egg/matchpy/expressions/expressions.py", line 667, in with_renamed_vars
return type(self)(self.name, variable_name=renaming.get(self.variable_name, self.variable_name))
TypeError: __init__() got an unexpected keyword argument 'variable_name'
This does not happen if I use a Wildcard.dot
object instead of ConstantSymbol
.
from matchpy.
On side note, the documentation website for MatchPy doesn't seems to be working properly. I dont see any documentation on this website:
http://matchpy.readthedocs.io/en/latest/api/matchpy.expressions.expressions.html
from matchpy.
Oh, thanks for the hint. I thought I had fixed the doc building process, but apparently it was still broken.
Now it should be fixed, you might need to refresh the page to see the new version.
from matchpy.
The problem is that your ConstantSymbol
inherits from Symbol
, but changes the __init__
signature.
The __init__
method needs to accept the variable_name
keyword:
class ConstantSymbol(Symbol):
...
def __init__(self, name: str, variable_name=None) -> None:
...
from matchpy.
This is the code for ConstantSymbol
(updated) but I am still getting the same error:
class ConstantSymbol(Symbol):
def __init__(self, value):
super(self.__class__, self).__init__(name=str(value), variable_name=None)
self.value = value
from matchpy.
Try this instead:
class ConstantSymbol(Symbol):
def __init__(self, value, variable_name=None):
super(self.__class__, self).__init__(name=str(value), variable_name=variable_name)
self.value = value
from matchpy.
It works. Thanks!
Can you explain what was wrong with the previous implementation?
from matchpy.
When renaming the variables in the expression, the new Expression is created with type(expr)(..., variable_name='new_name')
. In this example, the new symbol is created with ConstantSymbol(..., variable_name='new_name')
, but the __init__
does not accept variable_name
. Now that I think about it, you should probably override with_renamed_vars
in your ConstantSymbol
class, so that the value
property is set correctly.
from matchpy.
Related Issues (20)
- Need Help in code generation. HOT 7
- Not Compatible with Python 3.7 HOT 4
- 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
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.