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

Edit detail for #187 trouble with tuples revision 1 of 6

1 2 3 4 5 6
Editor:
Time: 2007/11/17 22:04:52 GMT-8
Note: infinite loop in parsing?

changed:
-
These error messages indicate some serious problems
with the Axiom Tuple domain::

  System error: The function |Domain| is undefined.
  The constructor Tuple takes 1 argument and you have given  2

Axiom allows functions to have a tuple as input but it
fails if a function generates two or more outputs.

For example:
\begin{axiom}
f:(INT,INT)->INT
g:INT->(INT,INT)
\end{axiom}
\begin{axiom}
(INT,INT)
\end{axiom}

'Tuple Any' should work in a similar way to 'List Any' and
'DirectProduct(2,Any)'.
\begin{axiom}
List Any
DirectProduct(2,Any)
Tuple Any
\end{axiom}

Axiom's non-homogeneous Record and Union domains are
functionally superior to the tuple construct but it makes
functional notation awkward. See [SandBox Direct Product]

<hr />
Try this (which gets around the error messages and bug):
\begin{axiom}
a:Tuple INT
a:=(1,2,3,4)
dom:=Tuple Any
b:dom:=(1::INT, 2::FLOAT,3::POLY INT)
h:INT->Tuple INT
h(x)==(x, 2+x)
h(5)
\end{axiom}

From billpage Wed Jun 29 01:43:26 -0500 2005
From: billpage
Date: Wed, 29 Jun 2005 01:43:26 -0500
Subject: Any suggestions
Message-ID: <20050629014326-0500@page.axiom-developer.org>

How to do composition of functions with two arguments and two outputs?

\begin{axiom}
f1:INT->Tuple INT
f1(x)==(x,2+x)
f2:(INT,INT)->INT
f2(x,y)==x*y
f2(f1(4))
f3:Tuple INT -> INT
f3(x) == *(x)
f3(f1(5))
\end{axiom}

<hr>
From: William Sit, July 1, 2005 06:26:00 -5:00<br>

The following works (not as neat as it should be, of course)

\begin{axiom}
f1:INT->Tuple INT
f1(x)==(x,2+x)
f2:(INT,INT)->INT
f2(x,y)==x*y
a:=f1(4)
f2(select(a,0), select(a,1))
f3:Tuple INT -> INT
f3(x) == reduce(*,[select(x,i::NNI) for i in 0..length(x)-1])
f3(a)
f3(f1(5))
f3((1,2,3,4)::Tuple INT)
f3 [1,2,3,4]
f4:Tuple INT -> List INT
f4 x == concat(x::List INT, x::List INT)
f4(f1(5))
\end{axiom}

Note that neither 'f3(1,2,3,4)' nor 'f3((1,2,3,4))' works, even though tuples are lists without the square brackets, essentially. In both cases, the reason is probably the parser treats the arities differently. Recall that the Interpreter (and Axiom) treats parenthesis as "applied to" (so 'f3 (1,2,3,4)' is the same as applying 'f3' to 4 distinct arguments and 'f3(a)' is 'f3 a'). I do think the second form should have worked without the explicit coercion.

I do not know why in the design of 'Tuple S', the parts are not to be referenced with just the usual list method like 'a.i' and must use 'select'. Also the indexing in 'Tuple S' starts with 0. In the very old days of Scratchpad, all aggregates indexing was zero based. Most are converted to one-based and you can have a choice. Somehow, 'Tuple S' was not updated to reflect this.

One final puzzle: In axiom output messages for (9) above, what is the 'G1433' (or whatever) function from 'Integer->Boolean'? I tried 

\begin{axiom}
)clear all
f3:Tuple INT->INT
f3 x == reduce(*,[select(x,i::NNI) for i in 0..length(x)-1])
a:Tuple INT:=(2,3)
f3 a
f3(a)
\end{axiom}

and there is no such function. Also, 'f3 a' actually works.

William

From unknown Fri Jul 1 06:49:16 -0500 2005
From: unknown
Date: Fri, 01 Jul 2005 06:49:16 -0500
Subject: display of tuple
Message-ID: <20050701064916-0500@page.axiom-developer.org>

Why tuples are displayed as list ? 

I prefer to read (2,3) or 2,3 for tuple, and ![2,3] only for lists.

Students and I make errors when the display is the same, even if there is a type information.

<hr>
From William Sit, Fri Jul 1 08:50:00 -0500 2005<br>

There seems to be some bug in the display, because the code in Tuple (array1.spad) uses parenthesis, not brackets.

\begin{axiom}
coerce(a)$Tuple INT
coerce(a)@PRIMARR INT
\end{axiom}

This "bug" may be due to the Interpreter coercing 'Tuple INT' to 'PRIMARR INT' and then to 'OutputForm', which perhaps uses the List output. The order of coercion may be governed by the conditional on coerce to 'Outputform' in 'Tuple S' ('S' needs to be of 'SetCategory').

William 

See related discussion: [Tuples Products And Records]

From wyscc Sun Oct 21 22:07:17 -0500 2007
From: wyscc
Date: Sun, 21 Oct 2007 22:07:17 -0500
Subject: infinite loop in parsing?
Message-ID: <20071021220717-0500@wiki.axiom-developer.org>

A named tuple cannot be assigned to a tuple of identifiers.
The last (commented out) line '[1 for (a,b) in g]' seems to cause a freeze in Axiom; no output, not even if )set mess bot on. If you try it by uncommenting the line, you have to use cancel. (It should have reported syntax error similar to '(a,b):=f' (although there shouldn't be an error because 'f' is of type 'Tuple (Positive) Integer'. However, even '(a,b):=(f::Tuple Integer)' does not work.)  This may be related to the convention that 'select' rather than 'apply' is used to get components in a tuple.

\begin{axiom}
)clear all
g:=[(1,2),(3,4)]
[(a:=e;(a,a)) for e in g]
[((a,b):=(select(e,0),select(e,1));(a,a,b,c)) for e in g]
f:=g.1
(a,b):=f
-- [1 for (a,b) in g]
\end{axiom}

On my system, the following message finally::

   >> System error:
   The storage for CONS is exhausted.
   Currently, 85895 pages are allocated.
   Use ALLOCATE to expand the space.

It's clearly an infinite loop.

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

These error messages indicate some serious problems with the Axiom Tuple domain:

  System error: The function |Domain| is undefined.
  The constructor Tuple takes 1 argument and you have given  2

Axiom allows functions to have a tuple as input but it fails if a function generates two or more outputs.

For example:

fricas
(1) -> f:(INT,INT)->INT
Type: Void
fricas
g:INT->(INT,INT)
The constructor Tuple takes 1 argument and you have given 2 .

fricas
(INT,INT)
LISP output: (UNPRINTABLE UNPRINTABLE)
Type: Tuple(Type)

Tuple Any should work in a similar way to List Any and DirectProduct(2,Any).

fricas
List Any

\label{eq1}\hbox{\axiomType{List}\ } \left({\hbox{\axiomType{Any}\ }}\right)(1)
Type: Type
fricas
DirectProduct(2,Any)

\label{eq2}\hbox{\axiomType{DirectProduct}\ } \left({2, \: \hbox{\axiomType{Any}\ }}\right)(2)
Type: Type
fricas
Tuple Any
LISP output: (UNPRINTABLE)
Type: Tuple(Type)

Axiom's non-homogeneous Record and Union domains are functionally superior to the tuple construct but it makes functional notation awkward. See [SandBox Direct Product]?


Try this (which gets around the error messages and bug):
fricas
a:Tuple INT
Type: Void
fricas
a:=(1,2,3,4)

\label{eq3}\left[ 1, \: 2, \: 3, \: 4 \right](3)
Type: Tuple(Integer)
fricas
dom:=Tuple Any

\label{eq4}\hbox{\axiomType{Tuple}\ } \left({\hbox{\axiomType{Any}\ }}\right)(4)
Type: Type
fricas
b:dom:=(1::INT, 2::FLOAT,3::POLY INT)

\label{eq5}\left[ 1, \:{2.0}, \: 3 \right](5)
Type: Tuple(Any)
fricas
h:INT->Tuple INT
Type: Void
fricas
h(x)==(x, 2+x)
Type: Void
fricas
h(5)
fricas
Compiling function h with type Integer -> Tuple(Integer)

\label{eq6}\left[ 5, \: 7 \right](6)
Type: Tuple(Integer)

Any suggestions --billpage, Wed, 29 Jun 2005 01:43:26 -0500 reply
How to do composition of functions with two arguments and two outputs?

fricas
f1:INT->Tuple INT
Type: Void
fricas
f1(x)==(x,2+x)
Type: Void
fricas
f2:(INT,INT)->INT
Type: Void
fricas
f2(x,y)==x*y
Type: Void
fricas
f2(f1(4))
fricas
Compiling function f1 with type Integer -> Tuple(Integer) 
   There are no library operations named f2 
      Use HyperDoc Browse or issue
                                 )what op f2
      to learn if there is any operation containing " f2 " in its name.
Cannot find a definition or applicable library operation named f2 with argument type(s) Tuple(Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.


From: William Sit, July 1, 2005 06:26:00 -5:00

The following works (not as neat as it should be, of course)

fricas
f1:INT->Tuple INT
Compiled code for f1 has been cleared.
Type: Void
fricas
f1(x)==(x,2+x)
1 old definition(s) deleted for function or rule f1
Type: Void
fricas
f2:(INT,INT)->INT
Type: Void
fricas
f2(x,y)==x*y
1 old definition(s) deleted for function or rule f2
Type: Void
fricas
a:=f1(4)
fricas
Compiling function f1 with type Integer -> Tuple(Integer)

\label{eq7}\left[ 4, \: 6 \right](7)
Type: Tuple(Integer)
fricas
f2(select(a,0), select(a,1))
fricas
Compiling function f2 with type (Integer, Integer) -> Integer

\label{eq8}24(8)
Type: PositiveInteger?
fricas
f3:Tuple INT -> INT
Type: Void
fricas
f3(x) == reduce(*,[select(x,i::NNI) for i in 0..length(x)-1])
Type: Void
fricas
f3(a)
There are 2 exposed and 5 unexposed library operations named length having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op length to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named length with argument type(s) Tuple(Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code.
fricas
Compiling function f3 with type Tuple(Integer) -> Integer 
   There are 2 exposed and 5 unexposed library operations named length 
      having 1 argument(s) but none was determined to be applicable. 
      Use HyperDoc Browse, or issue
                             )display op length
      to learn more about the available operations. Perhaps 
      package-calling the operation or using coercions on the arguments
      will allow you to apply the operation.
Cannot find a definition or applicable library operation named length with argument type(s) Tuple(Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

Note that neither f3(1,2,3,4) nor f3((1,2,3,4)) works, even though tuples are lists without the square brackets, essentially. In both cases, the reason is probably the parser treats the arities differently. Recall that the Interpreter (and Axiom) treats parenthesis as "applied to" (so f3 (1,2,3,4) is the same as applying f3 to 4 distinct arguments and f3(a) is f3 a). I do think the second form should have worked without the explicit coercion.

I do not know why in the design of Tuple S, the parts are not to be referenced with just the usual list method like a.i and must use select. Also the indexing in Tuple S starts with 0. In the very old days of Scratchpad, all aggregates indexing was zero based. Most are converted to one-based and you can have a choice. Somehow, Tuple S was not updated to reflect this.

One final puzzle: In axiom output messages for (9) above, what is the G1433 (or whatever) function from Integer->Boolean? I tried

fricas
)clear all
All user variables and function definitions have been cleared. f3:Tuple INT->INT
Type: Void
fricas
f3 x == reduce(*,[select(x,i::NNI) for i in 0..length(x)-1])
Type: Void
fricas
a:Tuple INT:=(2,3)

\label{eq9}\left[ 2, \: 3 \right](9)
Type: Tuple(Integer)
fricas
f3 a
There are 2 exposed and 5 unexposed library operations named length having 1 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op length to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a definition or applicable library operation named length with argument type(s) Tuple(Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. FriCAS will attempt to step through and interpret the code.
fricas
Compiling function f3 with type Tuple(Integer) -> Integer 
   There are 2 exposed and 5 unexposed library operations named length 
      having 1 argument(s) but none was determined to be applicable. 
      Use HyperDoc Browse, or issue
                             )display op length
      to learn more about the available operations. Perhaps 
      package-calling the operation or using coercions on the arguments
      will allow you to apply the operation.
Cannot find a definition or applicable library operation named length with argument type(s) Tuple(Integer)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.

and there is no such function. Also, f3 a actually works.

William

display of tuple --unknown, Fri, 01 Jul 2005 06:49:16 -0500 reply
Why tuples are displayed as list ?

I prefer to read (2,3) or 2,3 for tuple, and [2,3] only for lists.

Students and I make errors when the display is the same, even if there is a type information.


From William Sit, Fri Jul 1 08:50:00 -0500 2005

There seems to be some bug in the display, because the code in Tuple (array1.spad) uses parenthesis, not brackets.

fricas
coerce(a)$Tuple INT

\label{eq10}\left(2, \: 3 \right)(10)
Type: OutputForm?
fricas
coerce(a)@PRIMARR INT

\label{eq11}\left[ 2, \: 3 \right](11)
Type: PrimitiveArray?(Integer)

This "bug" may be due to the Interpreter coercing Tuple INT to PRIMARR INT and then to OutputForm, which perhaps uses the List output. The order of coercion may be governed by the conditional on coerce to Outputform in Tuple S (S needs to be of SetCategory).

William

See related discussion: [Tuples Products And Records]?

infinite loop in parsing? --wyscc, Sun, 21 Oct 2007 22:07:17 -0500 reply
A named tuple cannot be assigned to a tuple of identifiers. The last (commented out) line '[1 for (a,b) in g]? seems to cause a freeze in Axiom; no output, not even if )set mess bot on. If you try it by uncommenting the line, you have to use cancel. (It should have reported syntax error similar to (a,b):=f' (although there shouldn't be an error because f is of type Tuple (Positive) Integer. However, even (a,b):=(f::Tuple Integer) does not work.) This may be related to the convention that select rather than apply is used to get components in a tuple.

fricas
)clear all
All user variables and function definitions have been cleared. g:=[(1,2),(3,4)]

\label{eq12}\left[{\left(1, \: 2 \right)}, \:{\left(3, \: 4 \right)}\right](12)
Type: List(Tuple(PositiveInteger?))
fricas
[(a:=e;(a,a)) for e in g]

\label{eq13}\left[{\left({\left(1, \: 2 \right)}, \:{\left(1, \: 2 \right)}\right)}, \:{\left({\left(3, \: 4 \right)}, \:{\left(3, \: 4 \right)}\right)}\right](13)
Type: List(Tuple(Tuple(PositiveInteger?)))
fricas
[((a,b):=(select(e,0),select(e,1));(a,a,b,c)) for e in g]

\label{eq14}\left[{\left(1, \: 1, \: 2, \: c \right)}, \:{\left(3, \: 3, \: 4, \: c \right)}\right](14)
Type: List(Tuple(Polynomial(Integer)))
fricas
f:=g.1

\label{eq15}\left[ 1, \: 2 \right](15)
Type: Tuple(PositiveInteger?)
fricas
(a,b):=f
If there is a tuple on the left-hand side of an assignment then there must also be one on the right-hand side.

On my system, the following message finally:

   >> System error:
   The storage for CONS is exhausted.
   Currently, 85895 pages are allocated.
   Use ALLOCATE to expand the space.

It's clearly an infinite loop.