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

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/a6411b2f-2dfd-4088-bab1-6539f961915c%40hemmecke.org.

Reply via email to