> I can't see why something that should work the same every time suddenly
fails with an exception
Since you don't pass variables to the function, it's return value will
depend on the value of those variables in the calling context
```
def f():
return i
>>> for i in range(2): f()
...
0
1
```
/c
On Wednesday, April 20, 2022 at 3:23:44 AM UTC-5 [email protected] wrote:
> I am getting an exception where I don't see why it happens.
>
> The exception is:
> invalid input: Mod(1*(2*0) + 1*(1*1), (1*1)*(1*2))
>
> The statement where it is being thrown is:
> print(P3().subs(i, 0))
> exp = factor(expand(P3().subs(i, 0)))
>
> P3() should always return the same thing:
> def P3():
> exp = 2*i**2 + 4*i*j + 8*i*m - j**2 +2*m*j + 9*m**2
> return exp
>
> The print statement is just for debugging purposes. It shows me multiple
> times
> -j**2 + 2*j*m + 9*m**2
> then
> 9*m**2 + j*(2*m) - j**2 + (8*0)*m + (4*0)*j + 2*0**2
> invalid input: Mod(1*(2*0) + 1*(1*1), (1*1)*(1*2))
>
> So, I can't see why something that should work the same every time
> suddenly fails with an exception. The statement P3().subs(i, 0) should
> always return the same thing.
>
> A note on my coding style: P3 could easily be a global constant, but the
> function paradigm fits very well with the mathematics that I am
> reproducing. The most complex case I have runs recursively, which is very
> valuable. Also, I am using "exp" as a local variable that means
> "expression".
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/2b007cb5-b7bf-4ba9-b577-6ed340869a64n%40googlegroups.com.