5f892713c3 2021-03-03 trnsz@pobox.c: %%%%%%%%%%%%%%%%%%%%%
5f892713c3 2021-03-03 trnsz@pobox.c: % PROGRAMMING
5f892713c3 2021-03-03 trnsz@pobox.c: %%%%%%%%%%%%%%%%%%%%%
5f892713c3 2021-03-03 trnsz@pobox.c:
5f892713c3 2021-03-03 trnsz@pobox.c: % Define number to factorize
5f892713c3 2021-03-03 trnsz@pobox.c: x:=42;
5f892713c3 2021-03-03 trnsz@pobox.c:
5f892713c3 2021-03-03 trnsz@pobox.c: % Factorize x and write out each individual
5f892713c3 2021-03-03 trnsz@pobox.c: % factor
5f892713c3 2021-03-03 trnsz@pobox.c: factors:=factorize(fix(x))$
5f892713c3 2021-03-03 trnsz@pobox.c: x:=0$
5f892713c3 2021-03-03 trnsz@pobox.c: for i:=1:length(factors) do begin
5f892713c3 2021-03-03 trnsz@pobox.c: q:=part(factors,i);
5f892713c3 2021-03-03 trnsz@pobox.c: for j:=1:part(q,2) do begin
5f892713c3 2021-03-03 trnsz@pobox.c: x:=x+1;
5f892713c3 2021-03-03 trnsz@pobox.c: write "factor ", x, ": ", part(q,1);
5f892713c3 2021-03-03 trnsz@pobox.c: end;
5f892713c3 2021-03-03 trnsz@pobox.c: end;
5f892713c3 2021-03-03 trnsz@pobox.c:
5f892713c3 2021-03-03 trnsz@pobox.c: % Procedure to calculate Legendre polynomial
5f892713c3 2021-03-03 trnsz@pobox.c: % using recursion
5f892713c3 2021-03-03 trnsz@pobox.c: procedure p(n,x);
5f892713c3 2021-03-03 trnsz@pobox.c: if n<0 then rederr "Invalid argument to p(n,x)"
5f892713c3 2021-03-03 trnsz@pobox.c: else if n=0 then 1
5f892713c3 2021-03-03 trnsz@pobox.c: else if n=1 then x
5f892713c3 2021-03-03 trnsz@pobox.c: else ((2*n-1)*x*p(n-1,x)-(n-1)*p(n-2,x))/n$
5f892713c3 2021-03-03 trnsz@pobox.c:
5f892713c3 2021-03-03 trnsz@pobox.c: % Enable fancy output
5f892713c3 2021-03-03 trnsz@pobox.c: fancy_output$
5f892713c3 2021-03-03 trnsz@pobox.c:
5f892713c3 2021-03-03 trnsz@pobox.c: % Calculate p(2,w)
5f892713c3 2021-03-03 trnsz@pobox.c: write "P(2,w) = ", p(2,w);
5f892713c3 2021-03-03 trnsz@pobox.c:
5f892713c3 2021-03-03 trnsz@pobox.c: % Incidentally, p(n,x) can be calculated more
5f892713c3 2021-03-03 trnsz@pobox.c: % efficiently as follows
5f892713c3 2021-03-03 trnsz@pobox.c: procedure p(n,x);
5f892713c3 2021-03-03 trnsz@pobox.c: sub(y=0,df(1/(y^2-2*x*y+1)^(1/2),y,n))/(for i:=1:n product i)$
5f892713c3 2021-03-03 trnsz@pobox.c:
5f892713c3 2021-03-03 trnsz@pobox.c: write "P(3,w) = ", p(3,w);