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

Edit detail for #263 ContinuedFraction returns incorrect types revision 1 of 3

1 2 3
Editor:
Time: 2007/11/17 22:17:47 GMT-8
Note:

changed:
-
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
\begin{axiom}
)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)
ccfe(0,2::Fraction Integer)
\end{axiom}

'Fraction Fraction Integer' is also nonesense.

\begin{axiom}
ff1:Fraction Float
ff2:Fraction Fraction Integer
\end{axiom}


From kratt6 Fri Feb 3 03:24:30 -0600 2006
From: kratt6
Date: Fri, 03 Feb 2006 03:24:30 -0600
Subject: 
Message-ID: <20060203032430-0600@wiki.axiom-developer.org>

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:

\begin{axiom}
n := nume(0.2)
d := dene(0.2,x)
continuedFraction(0, n, d)
\end{axiom}

(note that there is no output...)

From BillPage Fri Feb 3 10:25:57 -0600 2006
From: Bill Page
Date: Fri, 03 Feb 2006 10:25:57 -0600
Subject: Re: Fraction R returns R when R is a field
Message-ID: <20060203102557-0600@wiki.axiom-developer.org>

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?


From kratt6 Mon Feb 6 08:01:14 -0600 2006
From: kratt6
Date: Mon, 06 Feb 2006 08:01:14 -0600
Subject: Re: Fraction R returns R when R is a field
Message-ID: <20060206080114-0600@wiki.axiom-developer.org>

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

From RalfHemmecke Mon Feb 6 10:08:22 -0600 2006
From: Ralf Hemmecke
Date: Mon, 06 Feb 2006 10:08:22 -0600
Subject: FRAC FRAC ID
Message-ID: <20060206100822-0600@wiki.axiom-developer.org>

Since "add { ... }" is a value in Aldor/Axiom, [Fraction] should/could be implemented as follows:

\begin{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
\end{spad}

Well, that means the representation of 'FRAC S' depends on whether S is already a field or not.

From BillPage Mon Feb 6 10:38:14 -0600 2006
From: Bill Page
Date: Mon, 06 Feb 2006 10:38:14 -0600
Subject: static types
Message-ID: <20060206103814-0600@wiki.axiom-developer.org>

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?


From BillPage Mon Feb 6 14:34:14 -0600 2006
From: Bill Page
Date: Mon, 06 Feb 2006 14:34:14 -0600
Subject: 
Message-ID: <20060206143414-0600@wiki.axiom-developer.org>

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:
\begin{axiom}
cff1:=continuedFraction(0,repeating [2],repeating [3])
4*cff1
cff2:=continuedFraction(0,repeating [1/2],repeating [1/3])
\end{axiom}

But the following code sends Axiom into an infinite loop::

  1/4*cff2


Submitted by : (unknown) at: 2007-11-17T22:17:47-08:00 (16 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

axiom
)set functions compile on nume(a) == cons(1,[((a-i)*i) for i in 1..]);
Type: Void
axiom
dene(a,x) == [(x+2*i+1-a) for i in 0..];
Type: Void
axiom
cfe(a,x) == continuedFraction(0,nume(a),dene(a,x));
Type: Void
axiom
ccfe(a,x) == convergents cfe(a,x);
Type: Void
axiom
ccfe(0,2::Float)
axiom
Compiling function nume with type NonNegativeInteger -> Stream 
      Integer
axiom
Compiling function dene with type (NonNegativeInteger,Float) -> 
      Stream Float
axiom
Compiling function cfe with type (NonNegativeInteger,Float) -> 
      ContinuedFraction Float
axiom
Compiling function ccfe with type (NonNegativeInteger,Float) -> 
      Stream Fraction Float
\begin{equation*} \label{eq1}\left[ {0.0}, \: {0.3333333333 3333333333}, \: {0.3571428571 4285714286}, \: {0.3604651162 7906976744}, \: {0.3611111111 1111111111}, \: {0.3612656467 3157162726}, \: {0.3613083856 8697077301}, \: {0.3613215638 624830248}, \: {0.3613259896 0595485929}, \: {0.3613275827 1362214001}, \: \ldots \right] \end{equation*}
Type: Stream Fraction Float
axiom
ccfe(0,2::Fraction Integer)
axiom
Compiling function dene with type (NonNegativeInteger,Fraction 
      Integer) -> Stream Fraction Integer
axiom
Compiling function cfe with type (NonNegativeInteger,Fraction 
      Integer) -> ContinuedFraction Fraction Integer
axiom
Compiling function ccfe with type (NonNegativeInteger,Fraction 
      Integer) -> Stream Fraction Fraction Integer
\begin{equation*} \label{eq2}\left[ 0, \: {1 \over 3}, \: {5 \over {14}}, \: {{31} \over {86}}, \: {{13} \over {36}}, \: {{1039} \over {2876}}, \: {{5291} \over {14644}}, \: {{20221} \over {55964}}, \: {{193003} \over {534152}}, \: {{385207} \over {1066088}}, \: \ldots \right] \end{equation*}
Type: Stream Fraction Fraction Integer

Fraction Fraction Integer is also nonesense.

axiom
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:

axiom
n := nume(0.2)
axiom
Compiling function nume with type Float -> Stream Float
\begin{equation*} \label{eq3}\left[ {1.0}, \: -{0.8}, \: -{3.6}, \: -{8.4}, \: -{15.2}, \: -{24.0}, \: -{34.8}, \: -{47.6}, \: -{62.4}, \: -{79.2}, \: \ldots \right] \end{equation*}
Type: Stream Float
axiom
d := dene(0.2,x)
axiom
Compiling function dene with type (Float,Variable x) -> Stream 
      Polynomial Float
\begin{equation*} \label{eq4}\left[ {x+{0.8}}, \: {x+{2.8}}, \: {x+{4.8}}, \: {x+{6.8}}, \: {x+{8.8}}, \: {x+{10.8}}, \: {x+{12.8}}, \: {x+{14.8}}, \: {x+{16.8}}, \: {x+{18.8}}, \: \ldots \right] \end{equation*}
Type: Stream Polynomial Float
axiom
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/zope2/var/LatexWiki/3103239194962224468-25px004.spad using 
      old system compiler.
******** Boot Syntax Error detected ********
The current line is:
    0> ... 
         ^
Currently preparsed lines are:
    1>  == if S has Field
    2>       then S add
    4>       else ...
    5>          add
The number of valid tokens is 1.
The current token is
Structure of type TOKEN 
Byte:[Slot Type]Slot Name   :Slot Value
   0:SYMBOL              :|..|
   8:TYPE                :GLIPH
  16:NONBLANK            :T
The prior token was
Structure of type TOKEN 
Byte:[Slot Type]Slot Name   :Slot Value
   0:SYMBOL              :|with|
   8:TYPE                :IDENTIFIER
  16:NONBLANK            :T

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:

axiom
cff1:=continuedFraction(0,repeating [2],repeating [3])
\begin{equation} \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 \end{equation}
Type: ContinuedFraction? Integer
axiom
4*cff1
\begin{equation} \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 \end{equation}
Type: ContinuedFraction? Integer
axiom
cff2:=continuedFraction(0,repeating [1/2],repeating [1/3])
\begin{equation} \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 \end{equation}
Type: ContinuedFraction? Fraction Integer

But the following code sends Axiom into an infinite loop:

  1/4*cff2
</pre>
<hr/><font size="-1" color="red">
Some or all expressions may not have rendered properly,
because Latex returned the following error:<br/><pre>
This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
 \write18 enabled.
entering extended mode
(./2033359089463550063-18px.tex
LaTeX2e &lt;2003/12/01&gt;
Babel &lt;v3.8d&gt; and hyphenation patterns for american, french, german, ngerman, b
ahasa, basque, bulgarian, catalan, croatian, czech, danish, dutch, esperanto, e
stonian, finnish, greek, icelandic, irish, italian, latin, magyar, norsk, polis
h, portuges, romanian, russian, serbian, slovak, slovene, spanish, swedish, tur
kish, ukrainian, nohyphenation, loaded.
(/usr/share/texmf-tetex/tex/latex/base/article.cls
Document Class: article 2004/02/16 v1.4f Standard LaTeX document class
(/usr/share/texmf-tetex/tex/latex/base/size10.clo))
(/usr/share/texmf-tetex/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/share/texmf-tetex/tex/latex/amsmath/amstext.sty
(/usr/share/texmf-tetex/tex/latex/amsmath/amsgen.sty))
(/usr/share/texmf-tetex/tex/latex/amsmath/amsbsy.sty)
(/usr/share/texmf-tetex/tex/latex/amsmath/amsopn.sty))
(/usr/share/texmf-tetex/tex/latex/amsfonts/amsfonts.sty)
(/usr/share/texmf-tetex/tex/generic/xypic/xy.sty
(/usr/share/texmf-tetex/tex/generic/xypic/xy.tex Bootstrap'ing: catcodes,
docmode, (/usr/share/texmf-tetex/tex/generic/xypic/xyrecat.tex)
(/usr/share/texmf-tetex/tex/generic/xypic/xyidioms.tex)

 Xy-pic version 3.7 &lt;1999/02/16&gt;
 Copyright (c) 1991-1998 by Kristoffer H. Rose &lt;krisrose@ens-lyon.fr&gt;
 Xy-pic is free software: see the User's Guide for details.

Loading kernel: messages; fonts; allocations: state, direction, utility macros; pictures: \xy, positions, objects, decorations; kernel objects: directionals, circles, text; options; algorithms: directions, edges, connections; Xy-pic loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xyall.tex Xy-pic option: All features v.3.3 (/usr/share/texmf-tetex/tex/generic/xypic/xycurve.tex Xy-pic option: Curve and Spline extension v.3.7 curve, circles, loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xyframe.tex Xy-pic option: Frame and Bracket extension v.3.7 loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xycmtip.tex Xy-pic option: Computer Modern tip extension v.3.3 (/usr/share/texmf-tetex/tex/generic/xypic/xytips.tex Xy-pic option: More Tips extension v.3.3 loaded) loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xyline.tex Xy-pic option: Line styles extension v.3.6 loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xyrotate.tex Xy-pic option: Rotate and Scale extension v.3.3 loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xycolor.tex Xy-pic option: Colour extension v.3.3 loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xymatrix.tex Xy-pic option: Matrix feature v.3.4 loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xyarrow.tex Xy-pic option: Arrow and Path feature v.3.5 path, \ar, loaded) (/usr/share/texmf-tetex/tex/generic/xypic/xygraph.tex Xy-pic option: Graph feature v.3.7 loaded) loaded)) (./2033359089463550063-18px.aux) (/usr/share/texmf-tetex/tex/latex/amsfonts/umsa.fd) (/usr/share/texmf-tetex/tex/latex/amsfonts/umsb.fd) Overfull \hbox (716.66875pt too wide) detected at line 16 [][] [1]?

Package amsmath Warning: Foreign command \over; (amsmath) \frac or \genfrac should be used instead (amsmath) on input line 20.

[2]? [3]? Overfull \hbox (71.04031pt too wide) detected at line 40 [][] [4]? Undefined control sequence. l.43 \label{eq5}\zag {2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ ...

Undefined control sequence. l.43 \label{eq5}\zag{2}{3}+ \zag {2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ ...

Undefined control sequence. l.43 \label{eq5}\zag{2}{3}+ \zag{2}{3}+ \zag {2}{3}+ \zag{2}{3}+ \zag{2}{3}+ ...

Undefined control sequence. l.43 ...5}\zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag {2}{3}+ \zag{2}{3}+ \zag{2...

Undefined control sequence. l.43 ...+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag {2}{3}+ \zag{2}{3}+ Undefined control sequence. l.43 ...+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag {2}{3}+ Undefined control sequence. l.44 \zag {2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+\ldots Undefined control sequence. l.44 \zag{2}{3}+ \zag {2}{3}+ \zag{2}{3}+ \zag{2}{3}+\ldots Undefined control sequence. l.44 \zag{2}{3}+ \zag{2}{3}+ \zag {2}{3}+ \zag{2}{3}+\ldots Undefined control sequence. l.44 \zag{2}{3}+ \zag{2}{3}+ \zag{2}{3}+ \zag {2}{3}+\ldots [5]? Undefined control sequence. l.48 \label{eq6}2+ \zag {1}{4}+ \zag{1}{{16}}+ \zag{1}{4}+ \zag{1}{{16}}+ \za...

Undefined control sequence. l.48 \label{eq6}2+ \zag{1}{4}+ \zag {1}{{16}}+ \zag{1}{4}+ \zag{1}{{16}}+ \za...

Undefined control sequence. l.48 \label{eq6}2+ \zag{1}{4}+ \zag{1}{{16}}+ \zag {1}{4}+ \zag{1}{{16}}+ \za...

Undefined control sequence. l.48 ...zag{1}{4}+ \zag{1}{{16}}+ \zag{1}{4}+ \zag {1}{{16}}+ \zag{1}{4}+ Undefined control sequence. l.48 ...{1}{{16}}+ \zag{1}{4}+ \zag{1}{{16}}+ \zag {1}{4}+ Undefined control sequence. l.49 \zag {1}{{16}}+ \zag{1}{4}+ \zag{1}{{16}}+ \zag{1}{4}+ \zag{1}{{16}}+\ldots

Undefined control sequence. l.49 \zag{1}{{16}}+ \zag {1}{4}+ \zag{1}{{16}}+ \zag{1}{4}+ \zag{1}{{16}}+\ldots

Undefined control sequence. l.49 \zag{1}{{16}}+ \zag{1}{4}+ \zag {1}{{16}}+ \zag{1}{4}+ \zag{1}{{16}}+\ldots

Undefined control sequence. l.49 ...{1}{{16}}+ \zag{1}{4}+ \zag{1}{{16}}+ \zag {1}{4}+ \zag{1}{{16}}+\ldots Undefined control sequence. l.49 ...zag{1}{4}+ \zag{1}{{16}}+ \zag{1}{4}+ \zag {1}{{16}}+\ldots [6]? Undefined control sequence. l.53 \label{eq7}\zag {{1 \over 2}}{{1 \over 3}}+ \zag{{1 \over 2}}{{1 \over 3...

Undefined control sequence. l.53 ...l{eq7}\zag{{1 \over 2}}{{1 \over 3}}+ \zag {{1 \over 2}}{{1 \over 3}}...

Undefined control sequence. l.53 ... 3}}+ \zag{{1 \over 2}}{{1 \over 3}}+ \zag {{1 \over Undefined control sequence. l.54 2}}{{1 \over 3}}+ \zag {{1 \over 2}}{{1 \over 3}}+ \zag{{1 \over 2}}{{1 ...

Undefined control sequence. l.54 ... 3}}+ \zag{{1 \over 2}}{{1 \over 3}}+ \zag {{1 \over 2}}{{1 \over Undefined control sequence. l.55 3}}+ \zag {{1 \over 2}}{{1 \over 3}}+ \zag{{1 \over 2}}{{1 \over 3}}+ \z...

Undefined control sequence. l.55 3}}+ \zag{{1 \over 2}}{{1 \over 3}}+ \zag {{1 \over 2}}{{1 \over 3}}+ \z...

Undefined control sequence. l.55 ... 3}}+ \zag{{1 \over 2}}{{1 \over 3}}+ \zag {{1 Undefined control sequence. l.56 \over 2}}{{1 \over 3}}+ \zag {{1 \over 2}}{{1 \over 3}}+ \zag{{1 \over 2...

Undefined control sequence. l.56 ... 3}}+ \zag{{1 \over 2}}{{1 \over 3}}+ \zag {{1 \over 2}}{{1 [7]? (./2033359089463550063-18px.aux) ) (see the transcript file for additional information) Output written on 2033359089463550063-18px.dvi (7 pages, 3164 bytes). Transcript written on 2033359089463550063-18px.log.