Lets recall again, that Diofant is nothing more than a Python library,
numpy or even the Python standard library module
sys. What this means is that Diofant does not add anything to
the Python language. Limitations that are inherent in the language
are also inherent in Diofant.
In this section we are trying to collect some things that could surprise newcomers.
>>> 3 + x**2 2 x + 3 >>> type(_ - x**2) <class 'diofant.core.numbers.Integer'>
But if you use some arithmetic operators between two numerical literals, Python will evaluate such expression before Diofant has a chance to get to them.
>>> x**(3/2) 1.5 x
The universal solution is using correct Diofant numeric class to
construct numbers explicitly. For example,
Rational in the above example
>>> x**Rational(3, 2) 3/2 x
You may think that
==, which is used for equality testing in
Python, is used for Diofant to test mathematical equality. This is
not quite correct either. Let us see what happens when we use
>>> (x + 1)**2 == x**2 + 2*x + 1 False
But, \((x + 1)^2\) does equal \(x^2 + 2x + 1\). What is going on here?
== represents structural equality testing and \((x +
1)^2\) and \(x^2 + 2x + 1\) are not the same in this sense. One is the
power and the other is the addition of three terms.
There is a separate class, called
Eq, which can be used to create a
>>> Eq((x + 1)**2 - x**2, 2*x + 1) 2 2 - x + (x + 1) = 2⋅x + 1
It is not always return a
bool object, like
==, but you
may use some simplification methods to prove (or disprove) equation.
>>> expand(_) true