Ralf Hemmecke
unread,May 2, 2024, 7:48:41 PM5/2/24Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to fricas-devel
Look at the following functions.
You might get trapped.
PP ==> PostiveInteger
C ==> Fraction Integer
expTruncated1(s: PP, t: C): C ==
z: C := 1 + t -- truncated exp
n: PP := 1 -- exponent for t
p: C := t -- power of t, p=t^n
f: C := 1 -- factorial, f=n!
while n < s repeat
n := n + 1;
p := p * t;
f := n * f;
z := z + p / f;
z
expTruncated2(s: PP, t: C): C ==
z: C := 1 + t -- truncated exp
n: PP := 1 -- exponent for t
p: C := t -- power of t, p=t^n
f: C := 1 -- factorial, f=n!
while n < s repeat
n := n + 1; p := p * t; f := n * f; z := z + p / f;
z
The expTruncated1 function behaves as expected.
The second function is not the same if the line following the "while"
keyword is enclosed in parentheses.
while n < s repeat
(n := n + 1; p := p * t; f := n * f; z := z + p / f);
Actually that is pretty clear since
while n < s repeat
n := n + 1; p := p * t; f := n * f; z := z + p / f;
and
while n < s repeat n := n + 1; p := p * t; f := n * f; z := z + p / f;
are the same according to the pile rules and then only the "n:=n+1"
belongs to the loop body and not the whole line.
So the code for expTruncated2 is OK, but somewhat hard to interpret for
the not-so-familiar eye.
Just a comment.
Ralf