#C18.txt March 26, 2018, ExpMath (RU) Help:=proc(): print(`RatToCF(x),NuToCF(x,n) , EvalCF(L), SymCF(a,n) `):end: #RatToCF(x): converts a pos. rational number x into a continued fraction RatToCF:=proc(x) local a,x1: if not (x>0 and type(x,rational)) then RETURN(FAIL): fi: a:=trunc(x): if a=x then RETURN([a]): fi: x1:=1/(x-a): [a, op(RatToCF(x1))]: end: #NuToCF(x,n): appx. a pos. number x into a continued fraction with <=n terms NuToCF:=proc(x,n) local a,x1: if not (x>0 and type(n,integer) and n>=1) then RETURN(FAIL): fi: a:=trunc(x): if n=1 then RETURN([a]): fi: if x=a then RETURN([a]): fi: x1:=1/(x-a): [a,op(NuToCF(x1,n-1))]: end: #EvalCF(L): evaluates the simple continued EvalCF:=proc(L) local L1,x: if not (type(L,list) and nops(L)>0) then RETURN(FAIL): fi: if nops(L)=1 then RETURN(L[1]): fi: L1:=[op(2..nops(L),L)]: x:=EvalCF(L1): normal(L[1]+1/x): end: #SymCF: the rational function of a[1], ..., a[n] describing EvalCF([a[1], ..., a[n]]): #the numerator followed by the denominator SymCF:=proc(a,n) local i,yonah: yonah:=EvalCF([seq(a[i],i=1..n)]): numer(yonah),denom(yonah): end: #The a-analog of the Fibonacci numbers, the numerator P:=proc(a,n) option remember: if n=0 then 1: elif n=1 then a[1]: else expand(a[n]*P(a,n-1)+ P(a,n-2)): end: Q:=proc(a,n) end: