On Mon, Jan 25, 2021 at 11:11:20AM -0800, Tobias Neumann wrote:
> Hello!
> 
> What is the best resource for SPAD? Aldor has a really excellent book
> ( https://www.aldor.org/docs/aldorug.pdf ) and I don't suppose that SPAD 
> has something similar? Presumably the FriCAS book ( 
> https://fricas.github.io/book.pdf ) and the FriCAS source are the best 
> resources? The FriCAS book covers SPAD in chapters 12 and 13, but I feel 
> it's not sufficient for me, especially when it comes to compiler errors.
> 
> I am currently struggling to implement functions around series expansions. 
> It's probably one of the most complicated situations to start with due to 
> the dependent types, but it's what I need :)

You will be looking at darkest corners of Spad compiler.  There
are bugs and limitations affecting series.  You can look at
existing algebra code to see how it deals with problems.

> My ultimate goal is to write a function (in a package) that takes an 
> expression for series expansion and the expansion point and returns the 
> series expansion. So basically as a first step I would just like to write a 
> simple wrapper around series/taylor/puiseux with fixed input/output types.

It is not clear for me what you really want to do (in FriCAS there
are already several different functions fitting your description
above).  For calling existing expanders you may look at
function 'expr_to_series' in 'src/algebra/mrv_limit.spad'.

BTW: 'taylor' already is a wrapper, so to see how wrappers works
you can look up code of 'taylor' in 'src/algebra/expr2ups.spad'.

BTW2: If you look up 'taylor' in HyperDoc you will see several
signatures, you need to tell Spad compiler which one you want
(for example by importing appropriate packege or via explicit
qualification that I did below).  Once you found correct
signature in HyperDoc 'descriptions' view you can click at
'Origin' field to see package description.  In package
description you can click at 'Source File' field to see
source file.  At least on my system title bar of source
window contains file name, so if you prefer you can use
different viewer to see the file (or fiddle a but with
environment variables so that HyperDoc invokes your
preffered viewer).
 
> I've tried this in a SPAD function:
>            x := 'x
>            ex := x :: Expression(Integer) 
>            eqn := (ex = 0)
>            testseries := taylor(x,eqn)
> 
> But the compiler complains about
>    >> Apparent user error:
>    NoValueMode
>     is an unknown mode
> 
> What does such an error mean?

Spad compiler has to deal with potentialy infinte set of types
and with overloading.  Also Spad lets you omit most type
annotations.  This means that Spad has to reconstruct missing
information.  Errors like above mean that Spad is unable to
find consistent types.  Spad can not be much more accurate
than this, partially due to internal limitations, partially
because huge (potentially infinte) number of possible
errors and fixes.  And yes, adding type/package annotations
is right thing to do.  

> I tried to get away with a minimal number of 
> type annotations, but adding additional for the taylor function doesn't 
> seem to help this error.

You need to be persistent.  AFAICS the following works:

-------------<cut here>----------------

)abbrev package MYTAYL MyTaylorExpansion

MyTaylorExpansion : with
    my_taylor : Expression(Integer) -> Any
  == add

    e_pak ==> ExpressionToUnivariatePowerSeries(Integer,
                  Expression(Integer))

    my_taylor(f) ==
        x := 'x
        ex := x :: Expression(Integer)      
        eqn := equation(ex, 0)$Equation(Expression(Integer))
        testseries := taylor(f, eqn)$e_pak

-------------<cut here>----------------

BTW: Error messages typically point to offending part, first
error pointed out to 'taylor' so it was easy to deduce that
I need to specify the package.  Then I got:

error in function my_taylor 

(SEQ (|:=| |x| '|x|) (|:=| |ex| (|::| |x| (|Expression| (|Integer|))))
     (|:=| |eqn| (= |ex| 0))
     (|exit| 1
      (|:=| |testseries|
       ((|Sel|
         (|ExpressionToUnivariatePowerSeries| (|Integer|)
                                              (|Expression| (|Integer|)))
         |taylor|)
        |f| | << eqn >> |))))
****** level 5  ******
$x:= eqn
$m:= (Equation (Expression (Integer)))
$f:=
((((|eqn| #) (|ex| #) (|x| #) (|f| # #) ...)))
 
   >> Apparent user error:
   Cannot coerce eqn 
      of mode (Boolean) 
      to mode (Equation (Expression (Integer)))

This told me that Spad took wrong type for 'ex = 0'.  So
I replaced '=' with 'equation'.  Then I got another
error about 'equation(ex, 0)' so I made it more specific.

> Furthermore, suppose I want to write a wrapper around taylor, could I write 
> the function with dependent types like this (I think something like this 
> would work in Aldor):
> 
> wrapper : (Expression(Integer), p:Expression(Integer), x0:Integer) -> 
> UnivariateTaylorSeries(Expression(Integer), p, x0)
> wrapper (expr, x, x0) == series(expr,x=x0)

No.  You can get similar effect to dependent types using extra
indirection via helper packages/domains, but in this case
extra indirection would defeat your purpose.

-- 
                              Waldek Hebisch

-- 
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/20210125230626.GA11077%40math.uni.wroc.pl.

Reply via email to