axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] [#187 trouoble with tuples] work around suggestion (if


From: wyscc
Subject: [Axiom-developer] [#187 trouoble with tuples] work around suggestion (if you must use Tuple)
Date: Fri, 01 Jul 2005 06:16:19 -0500

Changes 
http://page.axiom-developer.org/zope/mathaction/187TrouobleWithTuples/diff
--

++added:

<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  -- fixed typo
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: 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
\end{axiom}

and there is no such function.

William

--
forwarded from http://page.axiom-developer.org/zope/mathaction/address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]