> Bill Page wrote:
>> The original use case that I presented in another thread involved a
>> different use of "CatOf(R)". If it were possible to refer directly to
>> the category to which a domain belongs, then implementing
>> something similar to Aldor 'extend' would be easy in Spad
>
>>   MyInteger():CatOf(Integer) with
>>       ...
>>     == Integer add
>>       ...

On Wed, Dec 10, 2008 at 7:02 AM, Ralf Hemmecke wrote:
> OK, that should work if CatOf exists. But now suppose I want
> MyInteger to have a representation that is given by sticks, i.e. the
> integer 5 is represented in MyInteger as 11111 (or rather as the
> string "11111". Now, please implement MyInteger with this
> representation. (You are not allowed to look up the source code
> of Integer in order to find out what exports Integer provides.
> All you have is CatOf.

Since this is supposed to be an *extension* of Integer the underlying
representation can not change. Therefore I suppose that you do not
mean "representation" but rather "presentation", i.e. how a value of
MyInteger is to be displayed. That's easy - just override the coercion
to OutputForm.

(1) -> )sys cat myint.spad

)abbrev domain MYINT MyInteger
MyInteger(): Join(IntegerNumberSystem, ConvertibleTo String, OpenMath,_
  Canonical, canonicalsClosed)  with
    coerce: % -> OutputForm
    coerce: % -> Integer
  == Integer add
    coerce(x:%):OutputForm == message(concat(["1" for i in
1..abs(x)::Integer]))$OutputForm
    coerce(x:%):Integer == x pretend Integer

(1) -> )co myint.spad
   Compiling FriCAS source code from file /home/wspage/myint.spad using
      old system compiler.
   MYINT abbreviates domain MyInteger
------------------------------------------------------------------------
   MyInteger is already explicitly exposed in frame frame0
   MyInteger will be automatically loaded when needed from
      /home/wspage/MYINT.NRLIB/MYINT

(1) -> 3$MyInteger
   Loading /home/wspage/MYINT.NRLIB/MYINT for domain MyInteger

   (1)  111
                                                              Type: MyInteger
>
> If you manage to get MyInteger done, I will be surprised.
>

Perhaps I misunderstood your request. :-(

>> The domain MyInteger is then an extension of Integer.
>
> Yes that would be one use of CatOf, but "extend" is better. (IMHO)
>

Yes, agree. But my point is that 'CatOf' at least makes this much possible.

>> In less abstract terms 'S:CatOf(Integer)' simply means that
>> everywhere I use 'S' I can treat it exactly like 'Integer' even though
>> it may be a conceptually distinct domain. An example of something
>> like this already in the the FriCAS library is 'RomanNumeral'.
>
> And why not write IntegerNumberSystem instead of CatOf(Integer)?
> I don't see the gain of CatOf.
>

Because 'CatOf(Integer)' is

  Join(IntegerNumberSystem, ConvertibleTo String, OpenMath, Canonical,
canonicalsClosed)

>>
>> http://axiom-wiki.newsynthesis.org/LimitsAndColimits
>
> Now, I guess you are saying that Product and Sum should be taken
> as primitives in SPAD-CAT and not Record and Union.

Yes.

> Your implementation is not really what I was asking for. Now take
> your Product and Sum and show some code where it is superior
> to Record and Union. (If you like you can assume that Product
> and Sum work for arbitrarily many arguments. It's compiler supported
> in SPAD-CAT.)
>

If Product and Sum where built-in to some new version of SPAD they
would include the 'product' and 'sum' operations as an inherent part
of their definition. The existence of these operations is dictated by
describing them as categorical limits. So for example

f:Sum(Integer,Float)->Integer:=sum(abs$Integer,wholePart$Float)

That takes either an Integer or Float as argument and evaluates either
'abs' or 'wholePart' respectively to return an Integer.

(9) -> f(-1)
                          1
                                     Type: PositiveInteger

(10) -> f(3.14)
                          3
                                      Type: PositiveInteger

See: http://axiom-wiki.newsynthesis.org/LimitsAndColimits

This is written in Aldor because Aldor has somewhat better support for
Union than FriCAS.

Then for example the definition of a simple piecewise function might
look like this:

  p:Sum(NegativeInteger,ZeroInteger,PositiveInteger)->Integer :=
      sum(Integer,x +-> -(x^2), x +-> 0,x +-> x^2)

>>> How would a polynomial domain in infinitely many variables over
>>> some coefficient ring look like. Make it concrete.
>>
>> Re: "polynomial domain in infinitely many variables" ??? Isn't that
>> exactly what the domain 'Polynomial' is FriCAS is already? I don't
>> see that as a concrete example of what I am talking about.
>
> OK. I want a polynomial domain where every integer i is a variable
> (for better readability denote the variable i by x_i. Coefficients can
> come from any ring. No other variables are allowed. So in some
> sense the polynomial domain I am asking for does not allow kernels
> to count as variables. And you should program it in SPAD-CAT, not
> in SPAD. In SPAD we know. But how would it look like in a more
> categorical oriented language SPAD-CAT (the language you dream
> of)?
>

What makes you think that polynomials of the kind you describe should
look different in a more categorical-oriented language? I don't see
it.

>> For example, in the case of 'Product(X,Y)' the operation that is
>> required to exist and be uniquely defined is
>>
>>    product: (A:Type, A->X,A->Y) -> (A->%)
>>
>> for any domain A and functions A->X, A->Y.
>
> But I don't see how that helps me with programming. I don't just want
> to model a language but also use it later for concrete programs.
>

Generally speaking, higher-order functions like 'product' and 'sum'
help to make Spad in a more functionally-oriented language. Functional
programming is no longer just a "model language" and certainly used in
concrete programming problems.

Regards,
Bill Page.

--~--~---------~--~----~------------~-------~--~----~
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