real 1.0 / 5Q returns 1/5N not 0.2
diluculo opened this issue · 4 comments
I do some tests to understand how Approximation works by using SymbolicExpression.Parse(infix).
Infix string | Expression | RealValue | Note |
---|---|---|---|
1.2 | Approximation (Real 1.2) | 1.2 | |
1.0 + 1/5 | Approximation (Real 1.2) | 1.2 | |
1 + 1.0/5 | Number 6/5N | 1.2 | Bug? |
1 + 1/5 | Number 6/5N | 1.2 | |
6/5 | Number 6/5N | 1.2 | |
6.0/5 | Approximation (Real 1.2) | 1.2000000000000002 | |
6.0/5 - 6/5 | Approximation ... | 2.2204460492503131E-16 | Machine Epsilon |
When an inexact number, or a number with explicit decimal point is given in an expression, it should be approximated. It is strange that real 1.0 / 5Q
returns 1/5
not 0.2
. The problem is that the active pattern One
is used in multiply
.
real 1.0 / 5Q
-> multiply Approximation(Real 1.0) Number1/5N
-> multiply One Number1/5N
-> Number1/5N
.
One could indeed argue the One and MinusOne active patterns should not include approximative values. Maybe also Zero, although the floating point precicion is less of an issue there. A follow up question is then whether we still want 1.0/0.0
to simplify to complex infinity.
Thanks for quick answer. I got it. There are many hidden rules and layers. I thought simply it would be a good idea to add ExactOne
.
Yes, either that, or add ApproxOne and change the existing One to no longer include approximative values.
I've recently removed the parts where 1.0 was interpreted as 1 and 0.0 was interpreted as 0. I agree with the reasoning.
Infix string | Expression | RealValue | Note |
---|---|---|---|
1.2 | Approximation (Real 1.2) | 1.2 | |
1.0 + 1/5 | Approximation (Real 1.2) | 1.2 | |
1 + 1.0/5 | Approximation (Real 1.2) | 1.2 | (Fixed) |
1 + 1/5 | Number 6/5N | 1.2 | |
6/5 | Number 6/5N | 1.2 | |
6.0/5 | Approximation (Real 1.2) | 1.2 | |
6.0/5 - 6/5 | Approximation ... | 2.2204460492503131E-16 | Machine Epsilon |
I think this resolved this issue? Thanks again for bringing this up!