On Thu, Mar 01, 2012 at 11:04:57PM +0100, Ralf Hemmecke wrote:
> On 03/01/2012 09:58 PM, Serge D. Mechveliani wrote:
>> Thus, can Spad handle (I) ?  Something like this:
>>
>>    Category(R : CommutativeRing) : WithDet ==
>>      ...
>>      with
>>        det : SquareMatrix R ->  R
>>
>>        Default Implementation ==
>>
>>          det mt = if  rR has EuclideanRing  then
>>                                       gaussEliminationForEuclidean mt
>>                   else                genericMethod mt   -- expand by row
>>
>> -- correct the syntax if needed.
>
> ---rhxBEGIN foo.spad
> )abbrev domain FOO Foo
>
> Foo(R: Ring): with
>     coerce: % -> OutputForm
>     foo: R -> %
>   == add
>     Rep == R
>     coerce(x: %): OutputForm ==
>         "FoO"::OutputForm + (x pretend R)::OutputForm
>     if R has Field then
>       foo(r: R): % == (1/r) pretend %
>     else
>       foo(r: R): % == r pretend %
> ---rhxEND foo.spad
>
> Use it like this...
>
> (3) -> foo(3)$Foo(Integer)
>
>    (3)  FoO + 3
>                                    Type: Foo(Integer)
>
> (5) -> foo(3)$Foo(Fraction Integer)
>
>               1
>    (5)  FoO + -
>               3
>                                     Type: Foo(Fraction(Integer))
>

Thank you.
You changed from defining a Category to defining a Domain ...
All right, can `factor' be the dispatched by Axiom in this manner? 
So that the user would not search which package among 20 fits the best
for `factor'. 

------------------------------
)abbrev domain INT Integer
Integer(): with ...  
           Join(EuclideanDomain, UniqueFactorizationDomain ...)
  == add
   Rep == ?
   factor n == factorInteger

)abbrev domain SUP SparseUnivariatePolynomial
SparseUnivariatePolynomial(R : CommutativeRing): 
   with ...  
     Join(CommutativeRing, 
          R has IntegerLike  or  R has FiniteField  or 
            R has SuchAndSuchCategory  => UniqueFactorizationDomain
         )
  == add
   Rep == ?
   factor(f : UP R) : Factored (UP R) == 
            R has IntegerLike => factorUPOverInteger f
            R has FiniteField => factorUPByExtendedBerlekemp(R, f)
            R has SuchAndSuchCategory => factorUPByGeneric(R, f)
------------------------------

Usage:   factor(6) $INT,
         (f := (x^2 - 1) :: SUP INT;   factor(f) $SUP INT)

         (F := ResidueRing(INT, 7);  f := (x^7 +2) :: F;  factor(f)$F)

So Axiom will dispatch itself to the `factor' version which is the most 
efficient for this particular domain.
Can this be done?
I am trying to find out whether the language allows, in principle, a clear 
and efficient dispatching for such operations which have a complex set of 
implementation cases overlapping non-trivially and having different 
generality levels.  

Regards,

------
Sergei
[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