Martin Rubey wrote:
> Background: I'm trying to rewrite my previously posted implementation of
> the Dirichlet ring, using
> 
> PositveInteger -> Coef
> 
> as representation.  (I think this is more what I want in comparison to
> the representation Stream Coef)
> 
> However, I ran into a strange problem with "elt".  Namely, I do not
> manage to add an operation
> 
>     elt: (%, PositiveInteger) -> Coef
> 
> to the domain - but any other seems to be OK!  Here is what happens:
> 
> 
> (10) -> h(n: PI): INT  == n+1783
>    Function declaration h : PositiveInteger -> Integer has been added 
>       to workspace.
>    Compiled code for h has been cleared.
>    1 old definition(s) deleted for function or rule h 
>                                                                    Type:  Void
> (11) -> a := h::HI INT;
>    Compiling function h with type PositiveInteger -> Integer 
> 
>                                                        Type: HiThere(Integer)
> 
> 2) including the signature elt: (%, PositiveInteger) -> Coef (but
>    without it's implementation)
> ----------------------------------------------------------------------
> 
> (15) -> chk(a, 1)
> Function:  ?.? : (%,PositiveInteger) -> Integer is missing from domain: 
> HiThere(Integer)
>    Internal Error
>    The function elt with signature (Integer)$(PositiveInteger) is missing 
>       from domain HiThere(Integer) 
> 
> Note that chk shouldn't call elt$HiThere(Integer) at all!
> 
> 
> )abb package HI HiThere
> HiThere(Coef: Ring): SetCategory with
> 
>         coerce: (PositiveInteger -> Coef) -> %
>         chk: (%, PositiveInteger) -> Coef
> -- commenting out the following makes it "work"
>         elt: (%, PositiveInteger) -> Coef
> 
>     == add
>         FUN ==> PositiveInteger -> Coef
>         Rep := FUN
> 
>         chk(a: %, n: PositiveInteger): Coef ==
>             f: FUN := a pretend FUN
> -- how can I simply "evaluate" f.  It seems that FriCAS tries to call
>             elt...
>             x: Coef := f n
>             x

Partial explanation what happens: problematic line is

  f: FUN := a pretend FUN

FirCAS sees that function is needed so it effectively transforms
this to:

  f: FUN := z +-> (a pretend FUN)(z)

Next, it translates '(a pretend FUN)' to 'a' so gets

  f: FUN := z +-> a(z)

Now, elt give domain specific way to do function application, so
FriCAS transfors the above to

  f: FUN := z +-> elt(a, z)

Finally, FriCAS notices that body of lambda is a single call, so
replaces lambda by called function:

  f: FUN := elt

This final transformation is clearly incorrect: FriCAS does not
check if argument list matches -- this should be fixed.  The
inital transformation of 'a pretend FUN' to 'z +-> (a pretend FUN)(z)'
may look strange, but AFAICS is valid -- I will try to eliminate
this transformation, but IIRC ATM it is needed to correctly compile
stream code.

The transformation of a(z) to elt(a, z) is debatable.  On one hand
presumably user defined 'elt' so that compiler will do this
transformation.  OTOH 'a pretend FUN' has type FUN, so the
'a' should be considered of type 'FUN' for which there is no
such transformation.  I am not sure why exactly compiler decided
that this transform applies.  One possibility is that it knows
underlying type of 'a'.  Another is that FUN is Rep, so maybe it
silently converted Rep to %.

-- 
                              Waldek Hebisch
[email protected] 

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to