Origin for each line in Programming.red from check-in 5f892713c3:

5f892713c3 2021-03-03    1: %%%%%%%%%%%%%%%%%%%%%
5f892713c3 2021-03-03    2: %  PROGRAMMING
5f892713c3 2021-03-03    3: %%%%%%%%%%%%%%%%%%%%%
5f892713c3 2021-03-03    4: 
5f892713c3 2021-03-03    5: % Define number to factorize
5f892713c3 2021-03-03    6: x:=42;
5f892713c3 2021-03-03    7: 
5f892713c3 2021-03-03    8: % Factorize x and write out each individual 
5f892713c3 2021-03-03    9: % factor
5f892713c3 2021-03-03   10: factors:=factorize(fix(x))$
5f892713c3 2021-03-03   11: x:=0$
5f892713c3 2021-03-03   12: for i:=1:length(factors) do begin
5f892713c3 2021-03-03   13:    q:=part(factors,i);
5f892713c3 2021-03-03   14:    for j:=1:part(q,2) do begin
5f892713c3 2021-03-03   15:       x:=x+1;
5f892713c3 2021-03-03   16:       write "factor ", x, ": ", part(q,1);
5f892713c3 2021-03-03   17:    end;
5f892713c3 2021-03-03   18: end;
5f892713c3 2021-03-03   19: 
5f892713c3 2021-03-03   20: % Procedure to calculate Legendre polynomial
5f892713c3 2021-03-03   21: % using recursion 
5f892713c3 2021-03-03   22: procedure p(n,x);
5f892713c3 2021-03-03   23:    if n<0 then rederr "Invalid argument to p(n,x)"
5f892713c3 2021-03-03   24:    else if n=0 then 1
5f892713c3 2021-03-03   25:    else if n=1 then x
5f892713c3 2021-03-03   26:    else ((2*n-1)*x*p(n-1,x)-(n-1)*p(n-2,x))/n$
5f892713c3 2021-03-03   27: 
5f892713c3 2021-03-03   28: % Enable fancy output
5f892713c3 2021-03-03   29: fancy_output$
5f892713c3 2021-03-03   30: 
5f892713c3 2021-03-03   31: % Calculate p(2,w)
5f892713c3 2021-03-03   32: write "P(2,w) = ", p(2,w);
5f892713c3 2021-03-03   33: 
5f892713c3 2021-03-03   34: % Incidentally, p(n,x) can be calculated more
5f892713c3 2021-03-03   35: % efficiently as follows
5f892713c3 2021-03-03   36: procedure p(n,x);
5f892713c3 2021-03-03   37:    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   38: 
5f892713c3 2021-03-03   39: write "P(3,w) = ", p(3,w);

iCAS Bundled REDUCE Scripts
Homepage | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]