> And note that if the answer to the former question is yes, you lose
> this notational convenience:
> 
> sage: K.<x> = GF(5)[]
> sage: 2*x^2 + 3*x + 4
> 2*x^2 + 3*x + 4
> 
> You would instead have to type 2*x^2 + 3*x + GF(5)(4).

There are languages that still allow that to work without coercion.

What is happening below is that a literal (like 3) is just recognised as 
a (integer-like) literal. What that actually means in a certain domain 
is determined by a function

   integer: Literal -> %

(where % here basically stands for 'this domain'). So any domain that 
wants to understand integers just implements such a function. And if it 
is not yet there you provide it later (see below). Note that in the 
error message below, it is not complaining about the exponents. They 
must be of type MachineInteger, because the function

   ^: (%, MachineInteger) -> %

from P requires it and MachineInteger already provides an implementation for

   integer: Literal -> %

So in the end, in 2*x^3 (just by type checking) 2 is figured out to be 
in P and 3 in I. And of course the 4 below is also of type P so the 
addition is (P,P)->P (no coercion needed). Below x+i fails, because 
there is not function

   +: (P, I) -> P

Just a side remark in favour of non-dynamic typing. ;-)

Ralf

====================================================================

 >aldor -gloop
Aldor

Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org).

Release: Aldor(C) version 1.1.0 (trunk-23 AXL_EDIT_1_1_13_18=0) for 
LINUX(glibc2.3)
Type "#int help" for more details.
%1 >> #include "algebra"
%2 >> #include "aldorinterp"
%3 >> I==>MachineInteger -- That is basically a 32bit integer type.
%4 >> import from I, String, Symbol
%5 >> F5==SmallPrimeField 5
Defined F5 @ ? == SmallPrimeField(5)
%6 >> P==SparseUnivariatePolynomial(F5, -"x")
Defined P @ ? == SparseUnivariatePolynomial(F5, - "x")
%7 >> import from F5, P
%8 >> x: P := monom
x @ P
%9 >> 2*x^3 + 2*x + 4
       ^.......^
[L9 C1] #1 (Error) Argument 1 of `*' did not match any possible 
parameter type.
     The rejected type is MachineInteger.
     Expected one of:
       -- F5
       -- AldorInteger
       -- SparseUnivariatePolynomial(F5, - "x")

%10 >> integer(lit: Literal): P == (integer(lit)$Integer)::F5::P
Defined integer @ (lit: Literal) -> P
%11 >> 2*x^3 + 2*x + 4
2*x^3 + 2*x + 4 @ SparseUnivariatePolynomial(F5, - "x")
%12 >> i: I := 4
4 @ MachineInteger
%13 >> x+i
        ^
[L13 C1] #1 (Error) Argument 1 of `+' did not match any possible 
parameter type.
     The rejected type is P.
     Expected one of:
       -- String
       -- MachineInteger
       -- SmallPrimeField(5)

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to