Click on Ed's web-page to get back.

When programming, put a ; between commands. Let's play with a for-next loop. PARI does this for(variable=a,b,command) where a and b are integers you give it.

Try

for(n=1,10,print(n^2))

Try

for(n=1,10,print(n);print(n^2))

Try

for(n=1,10,print(n^2));print(n)

PARI can handle vectors. Type v=[10,9,8,7,6,5,4,3,2,1] You can pull out an entry like this: type v[1], on the next line type v[3].

Try

a=0;for(n=1,10,a=a+v[n];print(a))

To enter a matrix with three rows and two columns you could type

m=[1,2;3,4;5,6]

Let's play with if. PARI does this if(condition,command 1 ,command 2 ) The condition should include < or > or <> (the last is not equal). If the condition is true, then it will do command 1, if condition is not true it will do command 2. You can leave either command blank. Note issquare(n) outputs 1 if n is a square and 0 if it isn't.

Try

for(n=1,100,if(issquare(n)<>0,print(n),))

To plug something into an expression, use subst(expression, variable,replacement). So to evaluate x^2 + x + 1 at x=7 I would

f=x^2 + x + 1

subst(f,x,7)

Typing the square of every number not divisible by 3:

for(n=1,100,a=lift(mod(n,3));if(a<>0,print(n^2),))

To get a decimal approximation of a fraction like 18/19, then type 18/19 * 1.0

If you type \l, then everything that happens after that in your PARI session will be entered into a log file called pari.log in whatever directory you're in. Last changed: 4-Dec-2003