https://stackoverflow.com/questions/48839611/disabling-automatic-simplification-in-sympy#answer-48847102
A simpler way to disable automatic evaluation is to use context manager evaluate.
ただ
However, as the docstring of the context manager says, most of SymPy code expects automatic evaluation.
とあるので限定された用途しかなさそうですが。
結果例
python
1>>> with sympy.evaluate(False):
2... print(1/sympy.sqrt(2))
31/(sqrt(2))
help(sympy.evaluate)
の結果↓
plain
1Help on function evaluate in module sympy.core.parameters:
2
3evaluate(x)
4 Control automatic evaluation
5
6 Explanation
7 ===========
8
9 This context manager controls whether or not all SymPy functions evaluate
10 by default.
11
12 Note that much of SymPy expects evaluated expressions. This functionality
13 is experimental and is unlikely to function as intended on large
14 expressions.
15
16 Examples
17 ========
18
19 >>> from sympy import evaluate
20 >>> from sympy.abc import x
21 >>> print(x + x)
22 2*x
23 >>> with evaluate(False):
24 ... print(x + x)
25 x + x
python
1>>> with sympy.evaluate(False):
2... x = 1/sympy.sqrt(2)
3>>> x == 1/sympy.sqrt(2)
4False
5
6>>> x.equals(1/sympy.sqrt(2))
7True
ですよねー、という感じがしますね。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/12/05 04:06