python 2.7 - SymPy: simplifying of inverse function -


i define 2 sympy functions f, g, s.t. g inverse of f:

import sympy sy  g = sy.function('g')  class f(sy.function):     def inverse(self, argindex=1):         return g  x, y = sy.symbols('x y') print sy.solve(y - f(x), x) # [g(y)] - correct 

but if try evaluate f(g(x)) sympy doesnt simplify this:

print f(g(x))               # f(g(x)) print f(g(x)).doit()        # f(g(x)) - why not x? print f(g(x)).simplify()    # f(g(x)) - why not x? 

question: how sympy f(g(x)) x?

inverse isn't implemented that. opened https://github.com/sympy/sympy/issues/10487 it. ideally write below should work default.

you can make work defining _eval_simplify, like

class f(sy.function):     def inverse(self, argindex=1):         return g      def _eval_simplify(self, ratio, measure):         if isinstance(self.args[0], self.inverse()):             return self.args[0].args[0]         return self 

if have many classes want can put in superclass.

in [30]: f(g(x)) out[30]: f(g(x))  in [31]: f(g(x)).simplify() out[31]: x 

or if prefer doit() can define doit().


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -