Help:=proc(): print(`CF(a), CF1(a), IsPeriodic(L,p)`): print(` CFtoNu(L),CF1a(a,L), FindPeriod(L) ,GuessUP(L)`): print(`Paper(n) `): 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: #Paper(n): inputs a positive integer and outputs #a paper that proves the irrationality of sqrt(n) #by proving an explicit continued-fraction expansion Paper:=proc(n,A) local a,a1,a2,x,y,laurie,X,z: if type(sqrt(n),integer) then RETURN(`PerfectSquare`): fi: a:=GuessUP(CF1(evalf(sqrt(n)))): if a=FAIL then RETURN(FAIL): fi: a1:=a[1]: a2:=a[2]: laurie:=solve(normal(x-CFtoNu([op(a2),x])),x): x:=max(laurie): y:=CFtoNu([op(a1),x]): evalb(simplify(y^2-n)=0): print(`A Proof That `, sqrt(n), `is irrational`): print(): print(`By`, A ): print(): print(`Theorem: The square-root of`, n, `is irrational `): print(): print(`Proof: We will first prove a lemma`): print(): print(`Lemma: `, sqrt(n), `has the INFINITE continuted`): print(`fraction rep. starting with`, a1, `and followed by`): print(`repeats of`, a2, `ad infinitum `): print(): print(`Proof of Lemma: Let X be the number whose continued `): print(`fraction is`, a2, `repeated. then `, X=[op(a2),X] ): print(`Hence X satisfies the quadratic equation`): print(X=CFtoNu([op(a2),X])): print(`that is equivalent to`): print( numer(normal(X-CFtoNu([op(a2),X])))=0): print(`whose postive solution is`, x): print(`But the full continued fraction started with`, a1): print(`Hence the number represented is`): print(CFtoNu([op(a1),x])): print(`and this simplifies to`): z:=expand(rationalize(simplify(CFtoNu([op(a1),x])))): print(z): if not z=sqrt(n) then print(`Sorry, I messed up, no paper`): RETURN(FAIL): fi: print(`So the above-mentioned infinite contunued fraction`):`() print(`indeed equals`, sqrt(n) , `Quod Erat Demonstratum.`): print(): print(`Going back to the theorem, since`, sqrt(n), `has an`): print(`continued fraction, it follows that is indeed irrational`): print(`QED`): end: