Coder Social home page Coder Social logo

Comments (6)

wheerd avatar wheerd commented on June 7, 2024

from matchpy.

arihantparsoya avatar arihantparsoya commented on June 7, 2024

Thanks, I am facing another issue with ManyToOneReplacer:

>>> pattern2 = Pattern(Int(Pow(x_, m_), x), FreeQ((m,), x), NonzeroQ(Add(m_, one), (m,)))
>>> rule2 = ReplacementRule(pattern2, lambda m, x: Mul(Pow(x, Add(m, one)), Pow(Add(m, one), m_one)))
>>> subject2 = Int(Pow(x, one), x)
>>> replace_all(subject2, [rule2])
Mul(Pow(Add(ConstantSymbol('1'), ConstantSymbol('1')), ConstantSymbol('-1')), Pow(VariableSymbol('x'), Add(ConstantSymbol('1'), ConstantSymbol('1'))))
>>> rubi = ManyToOneReplacer(rule2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3-py3.6.egg/matchpy/matching/many_to_one.py", line 720, in __init__
  File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3-py3.6.egg/matchpy/matching/many_to_one.py", line 330, in add
  File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3-py3.6.egg/matchpy/matching/many_to_one.py", line 346, in _internal_add
  File "/Users/parsoyaarihant/anaconda/lib/python3.6/site-packages/matchpy-0.3-py3.6.egg/matchpy/matching/many_to_one.py", line 346, in <listcomp>
  File "/Users/parsoyaarihant/Rubi-MatchPy/Rubi/constraint.py", line 43, in with_renamed_vars
    copy = NonzeroQ()
TypeError: __init__() missing 2 required positional arguments: 'expr' and 'vars'

rule2 is being evaluated my replace_all but not by ManyToOneReplacer.

from matchpy.

arihantparsoya avatar arihantparsoya commented on June 7, 2024

This is happening due to presence of NonzeroQ:

class NonzeroQ(Constraint):
    def __init__(self, expr, vars):
        self.expr = expr
        self.vars = frozenset(v.name for v in vars)

    def __call__(self, substitution):
        return sympify(str(substitute(self.expr, substitution))) != 0

    @property
    def variables(self):
        return self.vars

    def with_renamed_vars(self, renaming):
        copy = NonzeroQ()
        copy.vars = frozenset(renaming.get(v, v) for v in self.vars)
        return copy

    def __eq__(self, other):
        return isinstance(other, NonzeroQ) and other.vars == self.vars and other.expr == self.expr

    def __hash__(self):
        return hash(self.vars)

from matchpy.

wheerd avatar wheerd commented on June 7, 2024

from matchpy.

wheerd avatar wheerd commented on June 7, 2024

New version 0.3.1 with this fix is up on PyPI.

from matchpy.

arihantparsoya avatar arihantparsoya commented on June 7, 2024

Thanks

from matchpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.