For the basic math operations addition, subtraction, multiplication, fractions and negate using integers is the following always true,
If any part of an operation is
indeterminate
the result isindeterminate
?
TL;DR
I am creating a symbolic math simplifier/evaluator in Prolog and am now working on fractions. I know the rule that if zero is in the denominator then the result is undefined
. After a bit of research I found that 0/0 is not undefined
but indeterminate
. So the obvious way to add the indeterminate
rules are to copy the rules for undefined
and check if both the numerator and denominator are zero and then define the result as indeterminate
. So far so good, I reached the rules such as adding, subtracting, multiplying and negating undefined
which say that if any part of an operation is undefined
the result is undefined
and was not sure that the same rules apply for indeterminate
.
The simplification rules are almost a direct translation of standard math rules but sometime require a guard
% simplify 21
% -X/-Y -> X/Y
simplify([op(frac),[[op(neg),X],[op(neg),Y]]], R) :-
X \= [number(0)],
Y \= [number(0)],
simplify([op(frac),[X,Y]], R),
!.
% simplify 22
% X/1 -> X
simplify([op(frac),[[number(X)],[number(1)]]], [number(X)]) :-
!.
As you can see these are term rewriting rules done in Prolog.
In the comments David K made a nice reference to NaN for which I am very familiar, (35+ years of programming). If this were using numerical methods I would find that acceptable, however this should only return answers that would be acceptable in a math course, such as undefined
or indeterminate
.
An example of a simple case that has me thinking
1/0 * 0/0
-> undefined * indeterminate
-> indeterminate, undefined or other?
as opposed to
1/0 * 4
-> undefined * 4
-> undefined
or
0/0 * 4
-> indeterminate * 4
-> indeterminate
If any of my statements are also wrong please let me know.
Latter on I will be adding reals, limits, etc., so if there is a different answer for those I don't expect an elaboration, just a simple note and I will ask the same question later when I get to those domains.
I tried to find where this is documented as in by definition
, but could not find it.
No comments:
Post a Comment