On 10/30/20 4:41 PM, Neven Sajko wrote:
> Thank you very much for your thoughtful responses, Ralf, I understand
> Spad a bit better now thanks to you. However it seems that another
> roadblock has appeared: while your lab1method1 works fine, lab1method2
> does not. At the end of the compilation there are warnings about the
> function BOOT::|DMLAB1;r| (which surely refers to the local function
> r) being undefined. Indeed, when I try to execute lab1method2 as I had
> lab1method1, I get the System error "The function BOOT::|DMLAB1;r| is
> undefined." and no other output.
>
> Do you know why this happens?
Indeed.
D ==> DirectProduct(3, Float)
x := directProduct(vector [1.1, 2.2, 3.3])$D
a := directProduct(vector [2.1, 3.2, 4.3])$D
(7) -> lab1method2(x, a, 2)
(7) 4.3
Type: Float
(8) -> lab1method2(x, a, 1)
(8) 3.2
Type: Float
(9) -> lab1method2(x, a, 3)
>> System error:
The function BOOT::|DMLAB1;r| is undefined.
Arrrrhhhh. Obviously the SPAD compiler is unable to deal with recursive
local functions. :-(
Waldek?
Ralf
PS: With a bit of macro magic, I have changed to making lab1method2
recursive. That seems to work, see attachment.
--
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/fe729318-45e9-2ca1-7ad1-26eb8a6deff5%40hemmecke.org.
)abbrev package DMLAB1 DiscreteMathLab1
DiscreteMathLab1() : Exports == Implementation where
D ==> DirectProduct(3, Float)
V ==> Vector Float
M ==> Matrix Float
N ==> NonNegativeInteger
Exports ==> with
lab1method1 : (D, D, N) -> Float
lab1method2 : (D, D, N) -> Float
Implementation ==> add
lab1method1(x : D, a : D, n : N) : Float ==
m: M := matrix [[(x.j^i)@Float for j in 1..3] for i in 0..2]
v: V := a :: V
sol: Union(V, "failed") := particularSolution(m, v)$LinearSystemMatrixPackage1(Float)
dot(directProduct(sol::V), map(z +-> z^n, x))
lab1method2(x : D, a : D, m: N): Float ==
r n ==> lab1method2(x, a, qcoerce(n)@N)
zero? m => a.1
m = 1 => a.2
m = 2 => a.3
(x.1+x.2+x.3) * r(m-1) _
- (x.1*x.2+x.2*x.3+x.3*x.1) * r(m-2) _
+ x.1*x.2*x.3 * r(m-3)