(10/19/2023, 11:49 AM)Shanghai46 Wrote: Btw I checked a bit and did a quick change of my code.
I erased p(x) from existence, and replaced it (in the if of tetra) by "n==int(n) and b==0". I also added a "if x==1, Z=(1,0)"
You can check if \(n\) is integer with \(\text{n.is_integer()}\). It works even if \(n\) is a float.
For a complex number
\(c=\text{complex(a,b)}\)
you can check:
\(\text{c.real.is_integer() and c.imag == 0}\)
Unless your calculation is unstable for small values of \(\text{c.imag}\), then may be convenient to check
\(\text{isclose(c.imag, 0)}\)
\(\text{isclose()}\) belongs to \(math\) module from which you imported everything, and allows to set the relative tolerance.