Help:=proc(): print(`CF(a), CF1(a,K), IsPeriodic(L,p)`): print(` CFtoNu(L),CF1a(a,L), FindPeriod(L) ,GuessUP(L)`): end: #CF(a): inputs a positive rational number and outputs #the list of terms in the (simple)-continued fraction CF:=proc(a) local b,c,L1: if a<0 or not type (a,rational) then ERROR(`We are followers of Pythagors`): fi: if type(a,integer) then RETURN([a]): fi: b:=trunc(a): c:=1/(a-b): L1:=CF(c): [b,op(L1)]: end: Digits:=100: #IsPeriodicP(L,p): inputs a list L and a pos. integer p #and outputs true if L is periodic of period p #starting at the beginning IsPeriodicP:=proc(L,p) local i: for i from 1 to nops(L)-p do if L[i]<>L[i+p] then RETURN(false): fi: od: true: end: #CFtoNu(L): inputs a list of integers and outputs #the rational number that is represents. CFtoNu:=proc(L): if nops(L)=1 then L[1]: else L[1]+1/CFtoNu([op(2..nops(L),L)]): fi: end: #AreWeDone(a,L): Given a real number a and a current #continued fraction appx. L, either returns L #(if the difference between a and "L" is less than 1/10^(Digits-10) #or a better L AreWeDone:=proc(a,L) if abs(a-CFtoNu(L))<1/10^(Digits-10) then true: else false: fi: end: CF1:=proc(a) local a1, b, L: a1:=evalf(a): b:=trunc(a1): L:=[b]: while not AreWeDone(a,L) do a1:=1/(a1-b): b:=trunc(a1): L:=[op(L),b]: od: L: end: #FindPeriod(L): inputs a list L and outputs #its shortest preiod FindPeriod:=proc(L) local p: for p from 1 to trunc(nops(L)/2) do if IsPeriodicP(L,p) then RETURN([op(1..p,L)]): fi: od: FAIL: end: #GuessUP(L): Inputs a list of integers L and outputs #two lists: L1, and L2, such that L=L1(L2)* GuessUP:=proc(L) local L1, L2,i: for i from 1 to trunc(nops(L)/2) do L1:=[op(1..i,L)]: L2:=[op(i+1..nops(L),L)]: L2:=FindPeriod(L2): if L2<>FAIL then RETURN(L1,L2): fi: od: FAIL: end: