sympy 任意函数范围 [英] sympy arbitrary function range

查看:31
本文介绍了sympy 任意函数范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义任意函数 f.我知道 f 总是返回一个正数.我希望 sympy 在运行简化时能够使用这些知识(尤其是简化文档中提到的三个幂规则).有没有办法做到这一点?我正在寻找类似下面的内容:

I want to define the arbitrary function f. I know that f always returns a positive number. I want sympy to be able to use this knowledge when running simplifications (especially the three power rules mentioned in the simplify documentation). Is there a way to do this? I'm looking for something like the below:

f = Function("f", positive = True)
g = Function("g", positive = True)
x = symbols("x")
y = symbols("y")
n = symbols("n", real = True)

test = ( f(x) * g(y) ) ** n
# This should work but doesn't
expand_power_base(test)

推荐答案

Function('f') 这样定义的函数目前不支持假设.您需要显式创建一个子类,例如

Functions defined like Function('f') do not support assumptions at this time. You'll need to create a subclass explicitly, like

class f(Function):
    is_positive = True

这篇关于sympy 任意函数范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆