jverzani / SymPyCore.jl

Package to help connect Julia with the SymPy library of Python
https://jverzani.github.io/SymPyCore.jl/
MIT License
5 stars 4 forks source link

Erroneous comparsion (>, <) results with oo and -oo and integers. #47

Closed MCurve7 closed 5 months ago

MCurve7 commented 5 months ago

When comparing the infinties oo and -oo with integers I get erroneous boolean results:

using SymPy

a=3

for i in -a:a
    println("-oo < $i: $(-oo < i)")
end
for i in -a:a
    println("oo < $i: $(oo < i)")
end

Results: -oo < -3: true -oo < -2: true -oo < -1: false -oo < 0: false -oo < 1: false -oo < 2: true -oo < 3: true and oo < -3: true oo < -2: true oo < -1: true oo < 0: false oo < 1: false oo < 2: true oo < 3: true I tested it out to -20:20 and the results were all true except as shown. Same results with <= and >=.

Julia version 1.10.0 SymPy version 1.12

jverzani commented 5 months ago

Thanks!

This is indeed unexpected and wrong. I put in a fix in #48, but hopefully it isn't deeper than that. (The compare method seems to give incorrect responses)

MCurve7 commented 5 months ago

Thank you for the quick response and for providing this package!

MCurve7 commented 5 months ago

I am not sure if I should open another Issue or if this is similair enough to the one I already opened. If I should open a new Issue let me know and I be happy to do so.

I have noticed a comparison issue with floats and positive infinity, oo.

using SymPy

a = 0.3

for i in -a:.1:a
    println("$i < oo: $(i < oo)")
end

for i in -a:.1:a
    println("-oo < $i: $(-oo < i)")
end

results in: -0.3 < oo: false -0.2 < oo: false -0.1 < oo: false 0.0 < oo: false 0.1 < oo: false 0.2 < oo: false 0.3 < oo: false I tested for a = 3.0 and got all false.

I also test -oo < i and it correctly resulted in true: -oo < -0.3: true -oo < -0.2: true -oo < -0.1: true -oo < 0.0: true -oo < 0.1: true -oo < 0.2: true -oo < 0.3: true

jverzani commented 5 months ago

Thanks! I'll have a look.

jverzani commented 5 months ago

Thanks. I failed to change an x to a y the first go round. Really appreciate you taking the time to report this.

MCurve7 commented 5 months ago

No problem and again thank you for you work.