|
|
last edited 16 years ago by kratt6 |
1 2 3 | ||
Editor: kratt6
Time: 2007/12/20 01:26:38 GMT-8 |
||
Note: |
added:
From kratt6 Thu Dec 20 01:26:38 -0800 2007
From: kratt6
Date: Thu, 20 Dec 2007 01:26:38 -0800
Subject:
Message-ID: <20071220012638-0800@axiom-wiki.newsynthesis.org>
Category: Axiom Mathematics => Axiom Library
There seems to be a problem with Axiom's ContinuedFractions? domain.
The type of the result is shown as Fraction Float
but this is
nonesense.
Something similar happens if the argument is Fraction Integer
)set functions compile on
nume(a) == cons(1,[((a-i)*i) for i in 1..]);
dene(a,x) == [(x+2*i+1-a) for i in 0..];
cfe(a,x) == continuedFraction(0, nume(a), dene(a, x));
ccfe(a,x) == convergents cfe(a, x);
ccfe(0,2::Float)
Compiling function nume with type NonNegativeInteger -> Stream( Integer)
Compiling function dene with type (NonNegativeInteger,Float) -> Stream(Float)
Compiling function cfe with type (NonNegativeInteger,Float) -> ContinuedFraction(Float)
Compiling function ccfe with type (NonNegativeInteger,Float) -> Stream(Fraction(Float))
(1) |
ccfe(0,2::Fraction Integer)
Compiling function dene with type (NonNegativeInteger,Fraction( Integer)) -> Stream(Fraction(Integer))
Compiling function cfe with type (NonNegativeInteger,Fraction( Integer)) -> ContinuedFraction(Fraction(Integer))
Compiling function ccfe with type (NonNegativeInteger,Fraction( Integer)) -> Stream(Fraction(Fraction(Integer)))
(2) |
Fraction Fraction Integer
is also nonsense.
ff1:Fraction Float
Fraction(Float) is not a valid type. ff2:Fraction Fraction Integer
Fraction(Fraction(Integer)) is not a valid type.
R
, it is often natural to return something of type Fraction R
. I see two possible solutions:
Fraction R
returns R
when R
is a fieldFraction R
has to check whether R
is a field.In the case above I see another problem:
n := nume(0.2)
Compiling function nume with type Float -> Stream(Float)
(3) |
d := dene(0.2,x)
Compiling function dene with type (Float,Variable(x)) -> Stream( Polynomial(Float))
(4) |
continuedFraction(0,n, d)
(note that there is no output...)
This makes very good sense to me. Is Field the right type or something more general?But is this possible in Axiom? How would I modify [Fraction]? to make this happen?
Thinking about it, I realized that this is not the proper solution, sinceFraction R
provides some operations, for example denominator
which R
does not necessarily have and I think it would be wrong to equip every Field
with this operation, which would then be necessary. Thus, either
Fraction Float
. In this case, denominator
will always return 1
, of course. Note that you can perfectly well calculate with objects of type Stream Fraction Fraction Integer
, no problem occurs. OrThe code that excludes constructions like FRAC FRAC
and FRAC R
when R
is a field is in clammed.boot.pamphlet
, lines 108-112.
Possibly we want to allow Fraction Field
but disallow Fraction Fraction
?
Martin
Since "add { ... }" is a value in Aldor/Axiom, [Fraction]? should/could be implemented as follows:Fraction(S: IntegralDomain): QuotientFieldCategory S with ... == if S has Field then S add -- additional functions like "denom" etc. else ... add -- old code goes here
Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/3103239194962224468-25px004.spad using old system compiler. ******** Spad syntax error detected ******** The current line is:
1> Fraction(S: IntegralDomain): QuotientFieldCategory S with ...
The number of valid tokens is 1. The prior token was #S(TOKEN :SYMBOL |with| :TYPE KEYWORD :NONBLANK NIL :LINE_NUM 1 :CHAR_NUM 53) The current token is #S(TOKEN :SYMBOL |..| :TYPE KEYWORD :NONBLANK NIL :LINE_NUM 1 :CHAR_NUM 58)
Well, that means the representation of FRAC S
depends on whether S is already a field or not.
I think Axiom's two-level type system is going to get in the way. Although it is true that types in Axiom are "first order objects" in the sense that we can assign them to variables etc., the kind of things that we can actually do with them is very limited. For example, I see no way in Axiom, SPAD or Aldor to have:
FRAC FRAC INT = FRAC INT
since FRAC INT
is static type and FRAC FRAC INT
is another
static type. In Axiom there is no way to write a function which
returns different types depending on it's parameters:
fType(x) == x=0 ==> Integer Float t:fType(1):=1.0
because types like Integer
and Float
are not members of some
domain in the same since in which 1
and -1
are members of
Integer
. And further there is no equality defined over types.
Or do I not understand something quite fundamental here?
Perhaps what you are suggesting amounts to ensuring that, as types these two are at least functionally equivalent?
Martin wrote:Note that you can perfectly well calculate with objects of type Stream Fraction Fraction Integer, no problem occurs.
I don't think you can calculate reliably with these strange types. I get bizarre results and sometimes Axiom crashes when I try things that should work. For example, this works:
cff1:=continuedFraction(0,repeating [2], repeating [3])
(5) |
4*cff1
(6) |
cff2:=continuedFraction(0,repeating [1/2], repeating [1/3])
(7) |
But the following code sends Axiom into an infinite loop:
1/4*cff2Category: Axiom Mathematics => Axiom Library