axiom-math
[Top][All Lists]
Advanced

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

Re: [Axiom-math] Axiom: Programming examples.


From: Francois Maltey
Subject: Re: [Axiom-math] Axiom: Programming examples.
Date: 28 Oct 2007 12:36:54 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Hello, 

(0) : 
The pretty print sqrt with the symbol \/--- is replaced by the
ROOT function for input longer than one line.


(1) :
> (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 


> (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.

> (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.

> (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.
 
> (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 := ...
 
> (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...

> (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 





reply via email to

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