The attached program results in the output given below.
Why is revb3 showing the empty list whereas lb3 does not?
Interestingly, when I remove the line marked with ***, then the output
for revb3 comes out as expected (see second session below).
It seems like assignment to "revb" inside "delay" is creating a new
variable revb that is not the same as the argument of restRecip. That's
the only possible explanation I can come up with.
Ralf
-- first session --
%%% (1) -> )co foo.spad
%%% (1) -> S ==> Stream Fraction Integer
%%% (2) -> )set stream calc 4
%%% (2) -> s: S := [i for i in 1..]
(2) [1, 2, 3, 4, ...]
%%% (3) -> un := (recip_new s)$Foo(Fraction Integer);
[:> , revb, [1]]
[:> , revb2, [1]]
[:> , lb2, [1]]
%%% (4) -> sn := un :: S;
%%% (5) -> sn.2
[:> , revb3, []]
[:> , lb3, [1]]
[:> , zero? bn, true]
[:> , revb, []]
[:> , revb2, []]
[:> , lb2, []]
(5) 0
-- second session
%%% (1) -> )co foo.spad
%%% (1) -> S ==> Stream Fraction Integer
%%% (2) -> )set stream calc 4
%%% (2) -> s: S := [i for i in 1..]
(2) [1, 2, 3, 4, ...]
%%% (3) -> un := (recip_new s)$Foo(Fraction Integer);
[:> , revb, [1]]
[:> , revb2, [1]]
[:> , lb2, [1]]
%%% (4) -> sn := un :: S;
%%% (5) -> sn.2
[:> , revb3, [1]]
[:> , lb3, [1]]
[:> , zero? bn, true]
[:> , revb, [1]]
[:> , revb2, [1]]
[:> , lb2, [1]]
(5) 0
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/bf073ae0-f74c-4328-acde-d68415eb816c%40gmail.com.
OF==>OutputForm
display77(x) ==> display((x::OF)::Formatter(Format1D))
yof x ==> x :: Symbol :: OF
dbgPrint(x,y) ==> display77([yof ":> ", yof x, y::OF]$List(OF))
)abbrev package FOO Foo
Foo(A) : Exports == Implementation where
A : Ring
I ==> Integer
NNI ==> NonNegativeInteger
ST ==> Stream
UN ==> Union(ST A,"failed")
Exports ==> with
recip_new: ST A -> UN
Implementation ==> add
restRecip(a: ST A, revb: List A, c0: A, n: I, k: I): ST A ==
dbgPrint("revb", revb)
empty? a => empty()
dbgPrint("revb2", revb)
lb: List A := revb
dbgPrint("lb2", lb)
delay
dbgPrint("revb3", revb)
dbgPrint("lb3", lb)
bn: A := 0
dbgPrint("zero? bn", zero? bn)
zero? bn => cons(bn, restRecip(a, revb, c0, n+1, k))
for i in k..n-1 repeat -- ***
revb := cons(0, revb) -- ***
dbgPrint("revbx", revb) -- ***
cons(bn, restRecip(a, cons(bn, revb), c0, n+1, n+1))
recip_new(x: ST A): Union(ST A, "failed") ==
empty? x => "failed"
ua: Union(A, "failed") := recip frst x
ua case "failed" => "failed"
b0: A := ua @ A
cons(b0, restRecip(rst x, [b0], - b0, 1, 1)) :: Union(ST A, "failed")
)clear complete
)time off
)co foo.spad
S ==> Stream Fraction Integer
)set stream calc 4
s: S := [i for i in 1..]
un := (recip_new s)$Foo(Fraction Integer);
sn := un :: S;
sn.2