login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Submitted by : (unknown) at: 2007-11-17T22:17:47-08:00 (9 years ago)
Name :
Axiom Version :
Category : Severity : Status :
Optional subject :  
Optional comment :

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

fricas
)set functions compile on
nume(a) == cons(1,[((a-i)*i) for i in 1..]);
Type: Void
fricas
dene(a,x) == [(x+2*i+1-a) for i in 0..];
Type: Void
fricas
cfe(a,x) == continuedFraction(0,nume(a),dene(a,x));
Type: Void
fricas
ccfe(a,x) == convergents cfe(a,x);
Type: Void
fricas
ccfe(0,2::Float)
fricas
Compiling function nume with type NonNegativeInteger -> Stream(
      Integer)
fricas
Compiling function dene with type (NonNegativeInteger,Float) -> 
      Stream(Float)
fricas
Compiling function cfe with type (NonNegativeInteger,Float) -> 
      ContinuedFraction(Float)
fricas
Compiling function ccfe with type (NonNegativeInteger,Float) -> 
      Stream(Fraction(Float))

\label{eq1}\begin{array}{@{}l}
\displaystyle
\left[{0.0}, \:{0.3333333333_3333333333}, \:{0.3571428571_428
5714286}, \: \right.
\
\
\displaystyle
\left.{0.3604651162_7906976744}, \:{0.3611111111_1111111111}, \: \right.
\
\
\displaystyle
\left.{0.3612656467_3157162726}, \:{0.3613083856_8697077301}, \: \right.
\
\
\displaystyle
\left.{0.3613215638_624830248}, \:{0.3613259896_0595485929}, \: \right.
\
\
\displaystyle
\left.{0.3613275827_1362214001}, \:...\right] 
(1)
Type: Stream(Fraction(Float))
fricas
ccfe(0,2::Fraction Integer)
fricas
Compiling function dene with type (NonNegativeInteger,Fraction(
      Integer)) -> Stream(Fraction(Integer))
fricas
Compiling function cfe with type (NonNegativeInteger,Fraction(
      Integer)) -> ContinuedFraction(Fraction(Integer))
fricas
Compiling function ccfe with type (NonNegativeInteger,Fraction(
      Integer)) -> Stream(Fraction(Fraction(Integer)))

\label{eq2}\left[ 0, \:{1 \over 3}, \:{5 \over{14}}, \:{{31}\over{86}}, \:{{13}\over{36}}, \:{{1039}\over{2876}}, \:{{5291}\over{1464
4}}, \:{{20221}\over{55964}}, \:{{193003}\over{534152}}, \:{{3
85207}\over{1066088}}, \:...\right](2)
Type: Stream(Fraction(Fraction(Integer)))

Fraction Fraction Integer is also nonsense.

fricas
ff1:Fraction Float
Fraction(Float) is not a valid type. ff2:Fraction Fraction Integer
Fraction(Fraction(Integer)) is not a valid type.

Well, this is a general problem: when a constructor takes a parameter 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 field
  • an operation that wants to return Fraction R has to check whether R is a field.

In the case above I see another problem:

fricas
n := nume(0.2)
fricas
Compiling function nume with type Float -> Stream(Float)

\label{eq3}\begin{array}{@{}l}
\displaystyle
\left[{1.0}, \: -{0.8}, \: -{3.6}, \: -{8.4}, \: -{15.2}, \: -{24.0}, \: -{34.8}, \: -{47.6}, \: -{62.4}, \right.
\
\
\displaystyle
\left.\: -{79.2}, \:...\right] 
(3)
Type: Stream(Float)
fricas
d := dene(0.2,x)
fricas
Compiling function dene with type (Float,Variable(x)) -> Stream(
      Polynomial(Float))

\label{eq4}\begin{array}{@{}l}
\displaystyle
\left[{x +{0.8}}, \:{x +{2.8}}, \:{x +{4.8}}, \:{x +{6.8}}, \:{x +{8.8}}, \:{x +{10.8}}, \:{x +{12.8}}, \: \right.
\
\
\displaystyle
\left.{x +{14.8}}, \:{x +{16.8}}, \:{x +{18.8}}, \:...\right] (4)
Type: Stream(Polynomial(Float))
fricas
continuedFraction(0, n, d)

(note that there is no output...)

Re: Fraction R returns R when R is a field --Bill Page, Fri, 03 Feb 2006 10:25:57 -0600 reply
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?

Re: Fraction R returns R when R is a field --kratt6, Mon, 06 Feb 2006 08:01:14 -0600 reply
Thinking about it, I realized that this is not the proper solution, since Fraction 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

  • Axiom's interpreter should not complain about types like 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. Or
  • operations that want to return Fraction R have to check whether R is a field.

The 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

FRAC FRAC ID --Ralf Hemmecke, Mon, 06 Feb 2006 10:08:22 -0600 reply
Since "add { ... }" is a value in Aldor/Axiom, [Fraction]? should/could be implemented as follows:

spad
Fraction(S: IntegralDomain): QuotientFieldCategory S with ...
 == if S has Field
      then S add 
         -- additional functions like "denom" etc.
      else ...
         add 
           -- old code goes here
spad
   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.

static types --Bill Page, Mon, 06 Feb 2006 10:38:14 -0600 reply
Ralf, do you think you could provide some example code that does this and actually works? I remain a little sceptical.

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:

fricas
cff1:=continuedFraction(0,repeating [2],repeating [3])

\label{eq5}\zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \ldots(5)
Type: ContinuedFraction?(Integer)
fricas
4*cff1

\label{eq6}2 + \zag{1}{4}+ \zag{1}{16}+ \zag{1}{4}+ \zag{1}{16}+ \zag{1}{4}+ \zag{1}{16}+ \zag{1}{4}+ \zag{1}{16}+ \zag{1}{4}+ \zag{1}{16}+ \ldots(6)
Type: ContinuedFraction?(Integer)
fricas
cff2:=continuedFraction(0,repeating [1/2],repeating [1/3])

\label{eq7}\zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \zag{1 \over 2}{1 \over 3}+ \ldots(7)
Type: ContinuedFraction?(Fraction(Integer))

But the following code sends Axiom into an infinite loop:

  1/4*cff2

Category: Axiom Mathematics => Axiom Library




  Subject:   Be Bold !!
  ( 13 subscribers )  
Please rate this page: