创建后如何更改SymPy符号的交换性? [英] How to change commutativity of a SymPy symbol after creation?

查看:26
本文介绍了创建后如何更改SymPy符号的交换性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我创建了一个 SymPy 符号 x.

Suppose I create a SymPy symbol x.

import sympy as sp
x = sp.Symbol('x', commutative = False)

如何在不创建新符号的情况下将交换假设更改为 True?我试过了

How can I change the commutative assumption to True without creating a new Symbol? I tried

with sp.assuming( sp.Q.commutative(x) ):
    print( sp.ask( Q.commutative(x) ) )

但它仍然给出False.

推荐答案

SymPy 对象是不可变的,所以这是不可能的.此外,新的假设系统(askQassuming)不支持 commutative.

SymPy objects are immutable, so this isn't possible. Furthermore commutative is not supported by the new assumptions system (ask, Q, assuming).

您应该做的是创建一个新符号并使用 subs 将其替换为您想要使其具有可交换性的任何表达式.

What you should do instead is create a new symbol and use subs to replace it in whatever expression you want to make it commutative in.

这篇关于创建后如何更改SymPy符号的交换性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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