سؤال

Why does this not work?

In: from sympy import *

    x = symbols('x', real=True)
    f = symbols('f', cls=Function, real=True)
    simplify(f(x)*conjugate(f(x)))

Out: f(x)*conjugate(f(x))

I expected f(x)**2.

هل كانت مفيدة؟

المحلول

Unfortunately, functions created with Function ignore assumptions. You'll need to create a function by subclassing Function, like

In [12]: class f(Function):
   ....:     is_real=True
   ....:

In [13]: f(x)
Out[13]: f(x)

In [14]: f(x).conjugate()
Out[14]: f(x)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top