#C3.txt: Jan. 28, 2016, Dr. Z.'s ExpMath class Help:=proc(): print(` FindPurePeriod1(L,k), FindPurePeriod(L) , FindPeriod(L) `): print(` CfSq(n), ListToN(L) `): end: Digits:=1000: #FindPeriod(L): inputs a list L and outputs two lists #[Beginning, PurePeriod] FindPeriod:=proc(L) local i,L1,M: for i from 1 to trunc(nops(L)/4) do L1:=L[i..nops(L)]: M:=FindPurePeriod(L1): if M<>FAIL then RETURN( [ [op(1..i-1,L)], M]): fi: od: FAIL: end: #FindPurePeriod(L): inputs a list L and tries to find a period of #length trunc(nops(L)/4) FindPurePeriod:=proc(L) local k,L1: for k from 1 to trunc(nops(L)/4) do L1:=FindPurePeriod1(L,k): if L1<>FAIL then RETURN(L1): fi: od: FAIL: end: #FindPurePeriod1(L,k): finds, if it exists that L is some list, M, of length k #repeated many times FindPurePeriod1:=proc(L,k) local N,i,a: N:=trunc(nops(L)/k): if [seq(seq(L[i],i=1..k),a=0..(N-1))]=[op(1..N*k,L)] then RETURN([op(1..k,L)]): else RETURN(FAIL): fi: end: #inputs a pos. integer, not a perfect square, and outputs two lists #L1,L2, such that sqrt(n) has the continued fraction [L1, L2^infinity] CfSq:=proc(n) local L,m: m:=evalf(sqrt(n)): if type(m, integer) then RETURN(FAIL): fi: L:=convert(m,confrac): L:=[op(1..trunc(nops(L)/2),L)]: FindPeriod(L): end: #ListToN(L): inputs a finite continued fraction and outputs its value ListToN:=proc(L) local L1: if nops(L)=1 then RETURN(L[1]): else RETURN(L[1]+1/ListToN([op(2..nops(L),L)])): fi: end: