Discussion:
[Axiom-math] Axiom: Programming examples.
C. Frangos
2007-10-27 12:26:57 UTC
Permalink
26 October 2007

Thanks very much to Bill Page, Time Daly, Francois Maltey and Waldeck Hebisch
for carefully going through my programming example below some time ago
and suggesting corrections.

Any assistance with the following would be appreciated:

(1) It would be very helpful if somebody could email me
basic programming examples in axiom demonstrating the
usage of the underscore _ at end of lines in combination with
basic programming constructs like nested for ...to... loops,
repeat ...until..., while...do..., if ,...then...else..., etc.
(I prefer the underscore to piles).

(2) In Matlab, there is a pause function which halts program execution
until any key is pressed. How can I construct a function in axiom
to do the same thing ??

(3) How can an expression be displayed as x1*cos(x2)+........, instead
of x1 cos(x2) +..... ??

(4) Are there accessible mathematical references that
clearly explain the theory of rings, categories, etc, and the relationship
with axiom rings, domains, categories etc ? (I have the axiom book and Tim
Daly's book).


(5) I uncommented the line
--testkinemat1() ==_
in the script below, in order to create a function from the script. However,
I get an error when I try to run the function from the command line.

(6) Are there additional simplification functions (user packages, etc
?) other than simplify() for expressions with complicated
trigonometric terms ?

(7) I want to mainly use local variables in function definitions. How are
local variables declared or defined in functions ??


TIA,

C. Frangos.



--testkinemat1() ==_

Acon := matrix([[1 , 0 , Lo1*sin(phi) , -sin(phi)*a , 0 , 0 , 0 , 0 , 0],_
[0 , 1 , -Lo1*cos(phi) , a*cos(phi) , 0 , 0 , 0 , 0 , 0],_
[1 , 0 , -Lo1*sin(phi) , 0 , -a*sin(phi), 0 , 0 , 0 , 0],_
[0 , 1 , Lo1*cos(phi) , 0 , a*cos(phi) , 0 , 0 , 0 , 0],_
[1,0,-Lc*cos(phi)+Lo1*sin(phi),0,0,0,-a*sin(phi)*cos(delta3)_
-a*cos(phi)*sin(delta3),0,0],_
[0,1,-Lc*sin(phi)-Lo1*cos(phi),0,0,0,a*cos(phi)*cos(delta3)_
-a*sin(phi)*sin(delta3),0,0],_
[1,0,-Lc*cos(phi)-Lo1*sin(phi),0,0,(-2*sin(phi)*Lo1*sin(delta3)-sin(phi)*_
Lc*cos(delta3)-cos(phi)*Lc*sin(delta3))*a/sqrt(4*Lo1^2*sin(delta3)^2+_
4*Lo1*sin(delta3)*Lc*cos(delta3)+Lc^2*cos(delta3)^2+Lc^2*sin(delta3)^2),0,0,0],_
[0,1,-Lc*sin(phi)+Lo1*cos(phi),0,0,a*(2*cos(phi)*Lo1*sin(delta3)+_
cos(phi)*Lc*cos(delta3)-sin(phi)*Lc*sin(delta3))/sqrt(4*Lo1^2*sin(delta3)^2+_
4*Lo1*sin(delta3)*Lc*cos(delta3)+Lc^2*cos(delta3)^2+Lc^2*sin(delta3)^2),0,0,0],_
[0 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , -k]])

Acon := simplify(Acon)

rankAcon := rank(Acon)

Acone := rowEchelon(Acon)

Aconnull := nullSpace(Acon)

nullity := nullity(Acon)
Francois Maltey
2007-10-28 11:36:54 UTC
Permalink
Hello,

(0) :
The pretty print sqrt with the symbol \/--- is replaced by the
ROOT function for input longer than one line.
Post by C. Frangos
(1) It would be very helpful if somebody could email me
basic programming examples in axiom demonstrating the
usage of the underscore _ at end of lines in combination with
basic programming constructs like nested for ...to... loops,
repeat ...until..., while...do..., if ,...then...else..., etc.
(I prefer the underscore to piles).
The _ means one line for axiom input.
I prefer pile but you can use _ if you prefer.

-- with piles
for k in 1..10
repeat
output (concat [k::String."*8=".(k*8)::String])

or

You must? use braces {} and separate instructions with semicolon ;
You can indent without any constraint.

With pile you can begin a new line everywhere but not at the outer piles
positions.
a :=
matrix [[..]] -- is right, the lines aren't indented.
a :=
matrix -- is wrong, the line are indented.


for k in 1..10 _
repeat_
{output (concat [k::String,"*8=",(k*8)::String])}

or

for k in 1..10 repeat {output (concat [k::String,"*8=",(k*8)::String])}

The Syracuse sequence :
u(0)=a in positive integer,
u(n+1)=u(n)/2 if n is even, and u(n+1)=3*u(n)+1
the result is the first n when u(n)=1

u := 123
n := 0
while u ~= 1
repeat
if even? u then -- the then is in the same line than if.
u := u/2
else
u := 3*u+1
n := n+1
n

or

u := 123
n := 0
while u ~= 1
repeat
if even? u then u := u/2 else u := 3*u+1
n := n+1
n

or

u := 123;_
n := 0;_
while u ~= 1 repeat_
{if even? u then u := u/2 else u := 3*u+1; n := n+1} ;_
n

I can't use the => operator for if-then-else tests.

u := 123
n := 0
while u ~= 1
repeat
n := n+1 --- must be placed before, the u:= 3*u+1 is the else case.
even? u => u := u/2
u := 3*u+1
n

MySeq a ==
u := a
n := 0
while u ~= 1
repeat
n := n+1 --- must be placed before, the u:= 3*u+1 is the else case.
if even? u then u := u/2 else u := 3*u+1
n
Post by C. Frangos
(2) In Matlab, there is a pause function which halts program execution
until any key is pressed. How can I construct a function in axiom
to do the same thing ??
I don't know how are read / input / sleep commands.
Post by C. Frangos
(3) How can an expression be displayed as x1*cos(x2)+........, instead
of x1 cos(x2) +..... ??
Do you know the text processor tex ?
You might get a tex output by tex (the expression)
There is also a fortran output command I believe.
Post by C. Frangos
(4) Are there accessible mathematical references that
clearly explain the theory of rings, categories, etc, and the relationship
with axiom rings, domains, categories etc ? (I have the axiom book and Tim
Daly's book).
The axiom book with 1.0e3 pages is THE reference.
rings and groups are mathematic terms in algebra.
domains and categories are the way that axiom try to translate
theses properties in a language. You can use axiom as a typed langage
and ignore the mathmeatics algebra.
Post by C. Frangos
(5) I uncommented the line
--testkinemat1() ==_
in the script below, in order to create a function from the script. However,
I get an error when I try to run the function from the command line.
This command works when there is no empty line between the header and
the Acon := ...
Post by C. Frangos
(6) Are there additional simplification functions (user packages, etc
?) other than simplify() for expressions with complicated
trigonometric terms ?
Can you simplify it with a pen ?
In this case it's possible to do it with computer algebra,
In the reponse is no I fear it's impossible.

The functions defined in axiom for trigonometric are in the file
.../mnt/linux/src/algebra/manip.spad
Look at the export part in the TranscendentalManipulations package
in this file.

axiom isn't intuitive for theses functions.
but they are presents...
Post by C. Frangos
(7) I want to mainly use local variables in function definitions. How are
local variables declared or defined in functions ??
I believe that all inner variables are local. Try :

fct a == {x := 7 ; a+x}
x := 100
fct 11
x
Martin Rubey
2007-10-28 12:52:47 UTC
Permalink
Post by Francois Maltey
You must? use braces {} and separate instructions with semicolon ;
You can indent without any constraint.
As far as I know this only works in Aldor!?
Post by Francois Maltey
Post by C. Frangos
(2) In Matlab, there is a pause function which halts program execution
until any key is pressed. How can I construct a function in axiom
to do the same thing ??
I don't know how are read / input / sleep commands.
You'll need to go to lisp to do that, maybe using read_-line()$Lisp
Post by Francois Maltey
Post by C. Frangos
(3) How can an expression be displayed as x1*cos(x2)+........, instead
of x1 cos(x2) +..... ??
maybe you like unparse(expr)::INFORM)
Post by Francois Maltey
Post by C. Frangos
(7) I want to mainly use local variables in function definitions. How are
local variables declared or defined in functions ??
Mostly. within local functions it doesn't seem to work reliably, although it should.

Martin

Loading...