Comparison of real numbers

Messages in english

Modérateur : xcasadmin

unixfan
Messages : 2
Inscription : mar. oct. 16, 2012 4:15 pm

Comparison of real numbers

Message par unixfan » mar. oct. 16, 2012 5:38 pm

Hi!

Is giac/xcas able to compare real numbers analytically? I tried this (version 0.9.9):

0>> exp(-10^10)<exp(-10^10-1)
0
// Time 0
1>> exp(-10^10)>exp(-10^10-1)
0
// Time 0
2>> exp(-10^10)==exp(-10^10-1)
0
// Time 0
3>> exp(-10^10)>=exp(-10^10-1)
1
// Time 0
4>> exp(-10^10)<=exp(-10^10-1)
1
// Time 0

I'm quite confused. Did I use it wrong? Does a>=b mean something different than a==b || a>b?

Peter

parisse
Messages : 5740
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Comparison of real numbers

Message par parisse » mar. oct. 16, 2012 6:02 pm

There is a difference between inequality tests and equality tests on symbolic expressions. For the first case, numerical evaluation is done before the test, for the second case the expressions are checked to be identical. That's why exp(-10^10) is neither < nor > to exp(-10^10-1) because they evalf to the same value (0.0).

unixfan
Messages : 2
Inscription : mar. oct. 16, 2012 4:15 pm

Re: Comparison of real numbers

Message par unixfan » mar. oct. 16, 2012 7:42 pm

parisse a écrit :There is a difference between inequality tests and equality tests on symbolic expressions. For the first case, numerical evaluation is done before the test, for the second case the expressions are checked to be identical. That's why exp(-10^10) is neither < nor > to exp(-10^10-1) because they evalf to the same value (0.0).
Thanks for your answer.

Is it possible to instruct giac not to perform numerical evaluation? In my simple example a non-numerical solution can be given easily by humans.
Another question: May I assume that a==b is only true if a is exactly b? If so, it would be possible to generate a pseudo-analytic solution: If a!=b analytically, it would be possible to increase the floating-point precision until a>b or b<a numerically. Yet another question: If giac cannot determine if a is exactly b, does it return a==b or some false/null-value?

parisse
Messages : 5740
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: Comparison of real numbers

Message par parisse » mer. oct. 17, 2012 7:11 am

I don't see how I could avoid numerical evaluation for inequality checking, think of an expression containing say ln(2), pi, sqrt(3), .... I could perhaps check again with improved numerical precision if the difference is smaller than something (e.g. 10^(2-number of digits)*sum of absolute values). But I'm almost certain that one could find examples where it would fail anyway.
For the a==b test, giac does the difference b-a and checks if it is zero. Since the - on symbolic expressions does not perform many checks, it should mean that a has the same internal representation as b once evaled, in that case the test returns 1 otherwise it returns 0. The best way to check if a is mathematically equal to b is to check if simplify(b-a) is zero. If it is not, it does unfortunately not prove that b is different from a, unless a and b belong to class of expressions that have a normal form (e.g. rational fractions).

Répondre