##################################################################### ## Reddy.txt Save this file as Reddy.txt to use it, # # stay in the # ## same directory, get into Maple (by typing: maple ) # ## and then type: read `Reddy.txt` # ## Then follow the instructions given there # ## # ## Written by Doron Zeilberger, Rutgers University , # ## DoronZeil at gmail dot com # ###################################################################### with(plots): print(`First Written: Sept. 8, 2026: tested for Maple 2025 `): print(`This Version: Sept. 8, 2026 `): print(): print(`This is Reddy.txt, a Maple package`): print(`accompanying Doron Zeilberger's article: `): print(` Approximating Pi (and other constants) by Radicals in the Footsteps of Rabbi Abraham Ibn Ezra and Guru RSJ Reddy`): print(): print(`The most current version is available on WWW at:`): print(` http://sites.math.rutgers.edu/~zeilberg/tokhniot/Reddy.txt .`): print(`Please report all bugs to: DoronZeil at gmail dot com .`): print(): print(`For general help, and a list of the MAIN functions,`): print(` type "ezra();". For specific help type "ezra(procedure_name);" `): print(`For a list of the less important procedures`): print(` type "ezra1();". For specific help type "ezra(procedure_name);" `): print(`For a list of the Story functions type: ezraSt();`): ezraSt:=proc() if args=NULL then print(`The Story procedures are: ReddyPaper1, ReddyPaper2 , ReddyPaper3, IbnEzraPaper `): else ezra(args): fi: end: ezra1:=proc() if args=NULL then print(`The supporting procedures are: BestNei, BestRadH1, BestRatBF, Err1, Neig `): else ezra(args): fi: end: ezra:=proc() if args=NULL then print(` Reddy.txt: A Maple package for approximating famous (and less famous) constants expressions of the form (a-b*C1)/c, where C1 is another constant(e.g.sqrt(2)) and b and c are small integers `): print(`The MAIN procedures are: BestRad, BestRadF, BestRadH, IbnEzra, IbnEzraCF, RestRat, ReddySeq `): print(``): elif nargs=1 and args[1]=BestNei then print(`BestNei(pt,C,C1,K,r): The best neighbor of the point pt with distance <=r , in trying to express C in terms of C1 in the form (a-pt[1]*C1)/pt[2] for pt in [0,K]^2. Try:`): print(`BestNei([5,5],Pi,sqrt(2),10,1);`): elif nargs=1 and args[1]=BestRad then print(`BestRad(C,C1,K): Given a constant C,and another constant, C1, finds the best approximation to Pi of the form (a-b*C1)/c for 1<=b,c <=K. It also returns the error. Try:`): print(`BestRad(Pi,sqrt(2),100).`): elif nargs=1 and args[1]=BestRadF then print(`BestRadF(C,C1,d): Given a constant C,and another constant, C1, and a pos. integer d, uses PSLQ to get an approximation to C in terms of C1 using floating-point d. Try:`): print(`BestRadF(Pi,sqrt(2),5);`): elif nargs=1 and args[1]=BestRadH then print(`BestRadH(C,C1,K,r,KAMA): Tries to find a good local apprx. by starting at random points and trying KAMA times`): print(`BestRadH(Pi,sqrt(2),30,1,10). `): elif nargs=1 and args[1]=BestRadH1 then print(`BestRadH1(pt,C,C1,K,r): Same as BestRad(C,C1,K) but by Hill climbing with neighnors of distance r/ It also returns the error. Try:`): print(`BestRadH1( [5,5],Pi,sqrt(2),10,1); `): elif nargs=1 and args[1]=BestRat then print(`BestRatBF(C,K): Given a constant c, finds the best rational approximations by the continued fraction , up to denominator K. Try:`): print(`BestRat(Pi,1000);`): elif nargs=1 and args[1]=BestRatBF then print(`BestRatBF(C,K): Given a constant c, finds the best rational approximations by brute force up to denominator K. Try:`): print(`BestRatBF(Pi,1000);`): elif nargs=1 and args[1]=Err1 then print(`Err1(pt,C,C1): Given a lattice point pt=[b,c] finds the error usint it to appx. C in terms of C1. Try:`): print(`Err1([1,2],Pi,sqrt(2));`): elif nargs=1 and args[1]=IbnEzra then print(`IbnEzra(C,C1,K): Given two constants C and C1 find the first K, best approx. of C in terms of C1*a/b, where each new term is a new record.`): print(`IbnEzra(Pi,sqrt(2),10);`): elif nargs=1 and args[1]=IbnEzraCF then print(`IbnEzraCF(C,C1,K): Given two constants C and C1 find the first K, best approx. of C in terms of C1*a/b, according to the convergents of the continued fraction of C/C1, where a and b are integers. Try:`): print(`IbnEzraCF(Pi,sqrt(2),10);`): elif nargs=1 and args[1]=IbnEzraPaper then print(`IbnEzraPaper(C,N,K): A paper that outputs The first K best rational approximations of the constant C as a/b*sqrt(n) for all non-square integers n from 2 to N. Try:`): print(`IbnEzraPaper(Pi,5,10);`): elif nargs=1 and args[1]=Neig then print(`Neig(pt,r,K): All the neighbors up to distance r of pt in [0,K]^2. Try:`): print(`Neig([3,3],1,10);`): elif nargs=1 and args[1]=ReddyPaper1 then print(`ReddyPaper1(C,N,K): inputs a constant C and a positive integer N and another pos. integer K, finds all best apprx. to C of the form (a-b*sqrt(n))/c for b,c<=K for all sqrt(n) where n<=N is not a perfect square,`): print(`it also returns the champion n at the end. Try:`): print(`ReddyPaper1(Pi,10,30);`): elif nargs=1 and args[1]=ReddyPaper2 then print(`ReddyPaper2(C,N,K): inputs a constant C and a posivie integer N and another pos. integer K finds all new ones with complexity for sqrt(n) for 2 to N. Try:`): print(`ReddyPaper2(Pi,7,30);`): elif nargs=1 and args[1]=ReddyPaper3 then print(`ReddyPaper3(C,7,K): inputs a constant C and a posivie integer N and another pos. integer K, uses the PSLQ algorithm to find good radical approximations with successive errors 10^(-k) up to K. Try:`): print(`ReddyPaper3(Pi,15,5);`): elif nargs=1 and args[1]=ReddySeq then print(`ReddySeq(C,C1,K): Given a constant C,and another constant, C1, finds the sequence best approximation to Pi of the form (a-b*C1)/c for 1<=a,b,c <=K, whevever a record is broken.`): print(`ReddySeq(Pi,sqrt(2),30).`): else print(`There is no such thing as`, args): fi: end: Digits:=100: #BestRatBF(C,K): Given a constant c, finds the best rational approximations by brute force up to denominator K. Try: #BestRatBF(Pi,1000) BestRatBF:=proc(C,K) local L, i,j,si,hal: L:=[]: i:=1: j:=round(C*i): si:=evalf(abs(C-j/i)): for i from 2 to K do j:=round(C*i): hal:=evalf(abs(C-j/i)): if halcu[1] then L:=[op(L),lu]: cu:=lu: fi: od: L: end: #ReddyPaper1(C,N,K): inputs a constant C and a posivie integer N and another pos. integer N finds all best apprx. to C of the form (a-b*sqrt(n))/c for b,c<=K for all sqrt(n) where n<=N is not a perfect square, #it also returns the champion n at the end. Try: #ReddyPaper1(Pi,10,30); ReddyPaper1:=proc(C,N,K) local t0,aluf,si,lu,n: t0:=time(): print(`Approximating `, C, ` in the form (a-b*sqrt(n))/c, for all n less than`, N, `and b and c less than `, K): print(``): print(`By Shalosh B. Ekhad `): print(``): si:=1: for n from 2 to N do if not type(sqrt(n), integer) then lu:=BestRad(C,sqrt(n),K): print(`The best approxmimation to`, C, ` in terms of`, sqrt(n), ` is `, lu[1]): if lu[2]siOld then RETURN(FAIL): else RETURN(aluf): fi: end: #BestRadH1(pt,C,C1,K,r): Same as BestRad(C,C1,K) but by Hill climbing starting at the point pt. with looking the best distance r neigbor #BestRadH1([5,5],Pi,sqrt(2),10). It also returns the error BestRadH1:=proc(pt,C,C1,K,r) local pt1,pt2, a: pt1:=pt: pt2:=BestNei(pt1,C,C1,K,r): while pt2<>FAIL do pt1:=pt2: pt2:=BestNei(pt1,C,C1,K,r): od: a:=round(pt1[2]*C+C1*pt1[1]): [(a-pt1[1]*C1)/pt1[2], Err1(pt1,C,C1)]: end: #BestRadH(C,C1,K,r,KAMA): Tries to find a good local apprx. by starting at random points and trying KAMA times #BestRadH(Pi,sqrt(2),30,1,10). BestRadH:=proc(C,C1,K,r,KAMA) local pt, aluf, si,i,hal: pt:=[K/2,K/2]: aluf:=BestRadH1(pt,C,C1,K,r): si:=aluf[2]: for i from 1 to KAMA do pt:=[rand(1..K)(),rand(1..K)()]: hal:=BestRadH1(pt,C,C1,K,r): if hal[2]mu1 then print(`This is the best you can do for b,c <=`, k-1): mu1:=mu2: print(`For b,c <=`, k, `The best approx. is`, mu1[1], `with error `, mu1[2]): fi: od: fi: od: print(`-------------------------`): print(``): print(`This ends this paper that took`, time()-t0, `seconds to make `): print(``): end: #IbnEzraCF(C,C1,K): Given two constants C and C1, and a pos. integer, K, find the first K best approximations of C in terms of C1*a/b, where a and b are integers. #Accoridng to the continued fraction. Try: #IbnEzra(Pi,sqrt(2),10); IbnEzraCF:=proc(C,C1,K) local gu,ka: gu:=convert(evalf(C/C1),confrac,ka): [op(1..K,ka)]: end: #BestNum1(c,b): given a constant c and a denominaor b, finds the best apprx. of the form a/b, followed by the error. Try: #BestNum1(Pi/sqrt(2),9); BestNum1:=proc(c,b) local c1,a: c1:=evalf(c*b): a:=round(c1): [a/b,evalf(abs(c-a/b))]: end: #IbnEzra(C,C1,,K): the first K champions in ratinal approximations to c by brute force. Try: #IbnEzra(Pi/sqrt(2),5); IbnEzra:=proc(C,C1,K) local c,gu,aluf,si,hal,i,mu: c:=C/C1: gu:=[]: mu:=BestNum1(c,1): aluf:=mu[1]: si:=mu[2]: for i from 2 while nops(gu)