Why can't I use D$UnivariateTaylorSeries(Expression...

6 views
Skip to first unread message

Neven Sajko

unread,
Aug 10, 2021, 1:00:57 PM8/10/21
to fricas-devel
Hello,

I notice that there is a function like this
D: (%, Symbol, NonNegativeInteger) -> %
in UnivariateTaylorSeries:
https://fricas.github.io/api/UnivariateTaylorSeries.html

Why then does this Spad program not compile:


)abbrev package XSMP XSomePack
XSomePack(): Exports == Implementation where

I ==> Integer

Exports ==> with

f: () -> I

Implementation ==> add

SYM ==> Symbol
EXPR ==> Expression(I)
TAY ==> UnivariateTaylorSeries(EXPR, 'x, 0$EXPR)

diff(t: TAY, s: SYM, n: NonNegativeInteger): TAY ==
D(t, s, n)$TAY

f(): I ==
0


This is the error message I get:

****** comp fails at level 2 with expression: ******
error in function diff

((|Sel|
(|UnivariateTaylorSeries| (|Expression| (|Integer|)) '|x|
(|Sel| (|Expression| (|Integer|)) 0))
D)
|t| | << s >> | |n|)
****** level 2 ******
$x:= s
$m:= (List (Symbol))
$f:=
((((|n| # #) (|s| # #) (|t| # #) (|diff| #) ...)))

>> Apparent user error:
Cannot coerce s
of mode (Symbol)
to mode (List (Symbol))


The compiler seems to think that it needs List Symbol instead of Symbol??


Thanks,
Neven

Waldek Hebisch

unread,
Aug 12, 2021, 9:06:23 PM8/12/21
to fricas...@googlegroups.com
On Tue, Aug 10, 2021 at 05:00:44PM +0000, Neven Sajko wrote:
> Hello,
>
> I notice that there is a function like this
> D: (%, Symbol, NonNegativeInteger) -> %
> in UnivariateTaylorSeries:
> https://fricas.github.io/api/UnivariateTaylorSeries.html
>
> Why then does this Spad program not compile:
>
>
> )abbrev package XSMP XSomePack
> XSomePack(): Exports == Implementation where
>
> I ==> Integer
>
> Exports ==> with
>
> f: () -> I
>
> Implementation ==> add
>
> SYM ==> Symbol
> EXPR ==> Expression(I)
> TAY ==> UnivariateTaylorSeries(EXPR, 'x, 0$EXPR)
^^^^^^
The error message you see is weakness in Spad compiler. Namely
D is exported only if EXPR has PartialDifferentialRing(Symbol).
There is workaround for this problem. But type like above is
currently does not work. You can probaby get desired effect
by creating extra package. So, first, make a general package:

)abbrev package XSMP0 XSomePack0
XSomePack0(s : Symbol, cen : EXPR): Exports == Implementation where

and use s and cen instead of 'x and 0$EXPR in the body.
To work around first issue use fake conditional like

TAY ==> UnivariateTaylorSeries(EXPR, s, cen)

if TAY has PartialDifferentialRing(Symbol) then

diff(t: TAY, s: SYM, n: NonNegativeInteger): TAY ==
D(t, s, n)$TAY

Finally, use another package to provide fixed parameters:

)abbrev package XSMP XSomePack
XSomePack(): Exports == Implementation where
I ==> Integer

Exports ==> with

f: () -> I

Implementation ==> XSomePack0("x"::Symbol,
0$Expression(Integer))

Bottom line: expressions must occur as runtime actions. As
I wrote, some issues related to expressions in types require
coordinated change in many places. They also require fixing
some related problems (and some are already fixed).

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages