######################################################################## ##AnomalousCancellation.txt: Save this file AnomalousCancellation.txt # ## To use it, stay in the # ##same directory, get into Maple (by typing: maple ) # ##and then type: read `AnomalousCancellation.txt` # ##Then follow the instructions given there # ## # ##Written by Doron Zeilberger, Rutgers University , # #DoronZeil at gmail dot com # ######################################################################## #Created: Aug. 2017 print(`Created: Aug. 2017`): print(` This is AnomalousCancellation.txt `): print(`It the Maple package that accompanies the article `): print(`Automated Generation of Anomalous Cancellations `): print(`by Shalosh B. Ekhad `): print(`and also available from Zeilberger's website`): print(``): print(`Please report bugs to DoronZeil at gmail dot com `): print(``): print(`The most current version of this package and paper`): print(` are available from`): print(`http://www.math.rutgers.edu/~zeilberg/ .`): print(`---------------------------------------`): print(`For a list of the Supporting procedures type ezra1();, for help with`): print(`a specific procedure, type ezra(procedure_name); .`): print(``): print(`---------------------------------------`): print(`---------------------------------------`): print(`For a list of the MAIN procedures type ezra();, for help with`): print(`a specific procedure, type ezra(procedure_name); .`): print(``): print(`---------------------------------------`): with(combinat): ezra1:=proc() if args=NULL then print(` The supporting procedures are: CB, CheckCand, DisFra, EAex, Eq, H, HA, Kick, LtoN, LtoS, OS, SolEq, Ta1, ToT, ToTg `): print(``): else ezra(args): fi: end: ezra:=proc() if args=NULL then print(`The main procedures are: AllAC, AllACtex, AllACnat, AllACvNat, AllACtexV, AllACv, AC, Boas, BookAC, BookACnat, BookACtex `): print(` `): elif nops([args])=1 and op(1,[args])=AllAC then print(`AllAC(d,b,k1,k2): The list of lists of pairs [A,B] in base b where B is a d-digit integer in base b and `): print(` if you remove the k1-th digit and k2-th digits (that must be the same) `): print(` and call the new numbers A',B' then A/B=A'/B'. Try: `): print(` AllAC(4,10,1,1); `): elif nops([args])=1 and op(1,[args])=AllACnat then print(`AllACnat(d,b,k1,k2): `): print(`The list if lists of pairs [A,B] in base b where B is a d-digit integer in base b and if you remove the k1-th digit and k2-th digits `): print(` (that must be the same) `): print(`and call the new numbers A',B' then A/B=A'/B'. Here the intgeres are represended in base b, but the digits are decimal. Try: `): print(`AllACnat(4,10,1,1);`): elif nops([args])=1 and op(1,[args])=AllACv then print(`AllACv(d,b,k1,k2): Verbose form of AllAC(d,b,k1,k2). Try:`): print(`AllACv(3,10,1,1);`): elif nops([args])=1 and op(1,[args])=AllACvNat then print(`AllACvNat(d,b,k1,k2): Verbose form of AllAC(d,b,k1,k2). Try:`): print(`AllACvNat(3,12,1,1);`): elif nops([args])=1 and op(1,[args])=AllACtex then print(`AllACtex(d,b,k1,k2): Like AllAC(d,b,k1,k2): but in TeX`): print(`The list if lists of pairs [A,B] in base b where B is a d-digit integer in base b and if you remove the k1-th digit and k2-th digits `): print(`(that must be the same)`): print(`and call the new numbers A',B' then A/B=A'/B'. Try: `): print(`AllACtex(4,10,1,1);`): elif nops([args])=1 and op(1,[args])=AllACtexV then print(`AllACtexV(d,b,k1,k2): Like AllACtex(d,b,k1,k2): but Verbosely. Try:`): print(`AllACtexV(4,10,1,1);`): elif nops([args])=1 and op(1,[args])=Boas then print(`Boas(B): All the anaomalous cancellations with 2 digits where the unit digit at the bottom cancells out with the "ten" digit of the top`): print(`for all bases up to B that are non-empty. It extens the tables on pp. 119-122 in R.P. Boas' beautiful article`): print(`"Anomalos Cancellation", in: "Mathematical Plums", Ross Honsberger, ed., Math. Assoc. of Amer., 1979`): print(`Try: `): print(` Boas(100); `): elif nops([args])=1 and op(1,[args])=BookAC then print(`BookAC(Maxd,b): inputs a positive integer Maxd, and a base b, and outputs a book in plain .txt, with all the anomalous cancellations in base b`): print(`with denominators that are between 2-digit to Maxd digits. Try:`): print(`BookAC(3,10);`): elif nops([args])=1 and op(1,[args])=BookACnat then print(`BookACnat(Maxd,b): inputs a positive integer Maxd, and a base b, and outputs a book with all the anomalous cancellations in base b`): print(`the denominators that are between 2-digit to Maxd diegits. Try:`): print(`BookACnat(3,14);`): elif nops([args])=1 and op(1,[args])=BookACtex then print(`BookACtex(Maxd,b): inputs a positive integer Maxd, and a base b, and outputs a book typset in TEX, with all the anomalous cancellations in base b`): print(`with denominators that are between 2-digit to Maxd digits. Try:`): print(`BookACtex(3,10);`): elif nops([args])=1 and op(1,[args])=CheckCand then print(`CheckCand(P,b,k1,k2): Given a pair of integres P in base b and non-neg. integers k1,k2`): print(`checks that the k1-digit of P[1] (in base b) is the same as the k2-digit of P[2], and`): print(`that "canelling" them is correct. Try: `): print(` CheckCand([16,64],10,0,1); `): elif nops([args])=1 and op(1,[args])=DisFra then print(`DisFra(L,i,j): inputs a pair of lists L, and integers i and j such that i is between 1 and nops(L[1]) and`): print(` j is between 1 and nops(L[2]) displays the cancellation L[1]/L[2], where i-th item is removed from `): print(` L[1] and the j-th from L[2]. Try: `): print(`DisFra([[1,2,3],[3,2,5]],2,2);`): elif nops([args])=1 and op(1,[args])=EAex then print(`EAex(m,n): inputs two integers and outputs integers c1 and c2 such that`): print(`c1*m+c1*n=1. Try: `): print(` EAex(19,67); `): elif nops([args])=1 and op(1,[args])=CB then print(`CB(N,b): converts N to base b`): elif nops([args])=1 and op(1,[args])=Eq then print(`Eq(N,b,k1,k2,x,y): inputs a denominator N, base b, integers k1, k2, and variables x,y, finds `): print(` an equation relating x and y such that if you place the k2-th digit of N into the k1-th digit of `): print(` the top and put x before it and y after it, and then do the Anomalous operation of cancelling `): print(`these digits you get a correct thing. Try: `): print(`Eq(64,10,1,0,x,y);`): elif nops([args])=1 and op(1,[args])=H then print(`H(d1,d2,b): all the pairs [n1,n2,i] where n1 and n2 are in base b with d1 and d2 digits respectively`): print(` where n1 and n2 share the digit i and removing it`): print(`cancelling by i) is true `): print(`WARNING: Pure brute force, for checking purposes only. DO NOT USE`): print(`Try:`): print(` H(2,2,10); `): elif nops([args])=1 and op(1,[args])=HA then print(`HA(d1,d2,b): Like H(d1,d2,b), but presents it in the base representation`): print(`WARNING: Pure brute force, for checking purposes only. DO NOT USE`): print(`Try: `): print(` HA(2,2,10); `): elif nops([args])=1 and op(1,[args])=AC then print(`AC(N,b,k1,k2): inputs a positive integer,N, (in base b), and k1, k2, non-neg. integers`): print(`outputs the set of integers M such that if, in the fraction M/N, the k2-digit of the denominator and k1-th digit of the`): print(`numerator are the same, and cancelling them out gives you something correct.`): print(` Try: `): print(` AC(99,10,0,1); `): elif nops([args])=1 and op(1,[args])=Kick then print(`Kick(L,a): kicks out a from L`): elif nops([args])=1 and op(1,[args])=LtoN then print(`LtoN(L,b): converts the list L in base b to its integer. Try: LtoB([1,2,3],10);`): print(``): elif nops([args])=1 and op(1,[args])=LtoS then print(`LtoS(L): List to string`): elif nops([args])=1 and op(1,[args])=OS then print(`OS(L): inputs a list of length 4, [m1,n1,f1,f2] `): print(`m1 and n1 are pos. integers m1>n1 and f1 and f2 are expressions`): print(`finds q and r such that m1=q*n1+r and returns [n1,r,f2,f1-q*f2]. In other words,`): print(` performs one step in the Euclidean algorithm. Try: `): print(` OS([17,13,A,B]); `): elif nops([args])=1 and op(1,[args])=SolEq then print(`SolEq(M,x,y,t): inputs an affine linear expression M in x,y, with integer coefficients`): print(`outputs the parametric solution of M=0 in terms of t. Try:`): print(`SolEq(2*x-3*y+1,x,y,t);`): elif nops([args])=1 and op(1,[args])=Ta1 then print(`Ta1(i) : equals i if 0<=i<=9, and then converts 10->A etc. 11->B , ... 35->Z `): elif nops([args])=1 and op(1,[args])=ToT then print(`ToT(P,b,k1,k2): converts the pair P in base b to a fraction in TeX where the k1-digit of P[1] and k2-digit is crossed-out. `): print(` Try: `): print(` ToT([457,875],10,0,1); `): elif nops([args])=1 and op(1,[args])=ToTg then print(`ToTg(P,b,k1,k2): converts a list of pairs LP in base b to a fraction in TeX where for each pair, the k1-digit of P[1] and k2-digit is crossed-out. `): print(` Try: `): print(` ToTg([[457,875]],10,0,1); `): else print(`There is no ezra for`,args): fi: end: ez:=proc(): print(` LtoN(L,b), Kick(L,a), H(d1,d2,b), Ha(d1,d2,b), LtoS(L), CB(N,b) `): end: ezN:=proc(): print(` Eq(N,b,k1,k2,x,y), OS([m,n,f1,f2]), EAex11(m,n), EAex1(m,n), EAex(m,n) , SolEq(M,x,y,t) , AC(N,b,k1,k2), AllAC(d,b,k1,k2) `): print(` ToT(P,b,k1,k2), AllACtex(d,b,k1,k2) , CheckCand(P,b,k1,k2), , AllACnat(d,b,k1,k2) `): end: #LtoN(L,b): converts the list L in base b to its integer. Try: LtoB([1,2,3],10); LtoN:=proc(L,b) local i: add(L[i]*b^(i-1),i=1..nops(L)): end: #Kick(L,a): kicks out a from L Kick:=proc(L,a) local i: for i from 1 to nops(L) while L[i]<>a do od: if i=nops(L)+1 then FAIL: else [op(1..i-1,L),op(i+1..nops(L),L)]: fi: end: #CB(N,b): converts N to base b CB:=proc(N,b) local N1,i: N1:=convert(N,base,b): [seq(N1[nops(N1)+1-i1],i1=1..nops(N1))]: end: #H(d1,d2,b): all the pairs [n1,n2,i] where n1 and n2 are in base b, where n1 and n2 share the digit i and removing it #("cancelling" by i) is true H:=proc(d1,d2,b) local n1,n2,N1,N2,i,lu,M1,M2,m1,m2,gu: gu:={}: for n1 from b^(d1-1)+1 to b^d1-1 do N1:=convert(n1,base,b): for n2 from n1+1 to b^d2-1 do N2:=convert(n2,base,b): lu:= convert(N1,set) intersect convert(N2,set): if nops(lu)=1 then i:=lu[1]: M1:=Kick(N1,i): M2:=Kick(N2,i): m1:=LtoN(M1,b): m2:=LtoN(M2,b): if (n2<>0 and m2<>0 and not type(n1/b,integer) and not type(n2/b,integer) and not nops(convert(N1,set))=1 and not nops(convert(N2,set))=1) then if n1/n2=m1/m2 then gu:=gu union {[n1,n2,i]}: fi: fi: fi: od: od: gu: end: haf:=proc(L) local i: [seq(L[nops(L)-i+1],i=1..nops(L))]: end: #LtoS(L): List to string LtoS:=proc(L) local gu,i: if L=[] then RETURN(NULL): fi: gu:=Ta1(L[1]): for i from 2 to nops(L) do gu:=cat(gu,Ta1(L[i])): od: gu: end: #Ta1(i) : converts 10->A etc. Ta1:=proc(i) if i<=9 then RETURN(i): elif i=10 then RETURN(`A`): elif i=11 then RETURN(`B`): elif i=12 then RETURN(`C`): elif i=13 then RETURN(`D`): elif i=14 then RETURN(`E`): elif i=15 then RETURN(`F`): elif i=16 then RETURN(`G`): elif i=17 then RETURN(`H`): elif i=18 then RETURN(`I`): elif i=19 then RETURN(`J`): elif i=20 then RETURN(`K`): elif i=21 then RETURN(`L`): elif i=22 then RETURN(`M`): elif i=23 then RETURN(`N`): elif i=24 then RETURN(`O`): elif i=25 then RETURN(`P`): elif i=26 then RETURN(`Q`): elif i=27 then RETURN(`R`): elif i=28 then RETURN(`S`): elif i=29 then RETURN(`T`): elif i=30 then RETURN(`U`): elif i=31 then RETURN(`V`): elif i=32 then RETURN(`W`): elif i=33 then RETURN(`X`): elif i=34 then RETURN(`Y`): elif i=35 then RETURN(`Z`): else RETURN(convert(i,string)): fi: end: #HA(d1,d2,b): Like H(d1,d2,b): but also displays the representation in the base #all the pairs [n1,n2,i] where n1 and n2 are in base b, where n1 and n2 share the digit i and removing it #("cancelling" by i) is true HA:=proc(d1,d2,b) local n1,n2,N1,N2,i,lu,M1,M2,m1,m2,gu: gu:={}: for n1 from b^(d1-1)+1 to b^d1-1 do N1:=convert(n1,base,b): for n2 from n1+1 to b^d2-1 do N2:=convert(n2,base,b): lu:= convert(N1,set) intersect convert(N2,set): if nops(lu)=1 then i:=lu[1]: M1:=Kick(N1,i): M2:=Kick(N2,i): m1:=LtoN(M1,b): m2:=LtoN(M2,b): if (n2<>0 and m2<>0 and not type(n1/b,integer) and not type(n2/b,integer) and not nops(convert(N1,set))=1 and not nops(convert(N2,set))=1) then if n1/n2=m1/m2 then gu:=gu union {[LtoS(haf(N1)),LtoS(haf(N2)),Ta1(i)]}: fi: fi: fi: od: od: gu: end: #Eq(N,b,k1,k2,x,y): inputs a denominator N, base b, integers k1, k2, and variables x,y, find #an equation relating x and y such that if you place the k2-th digit of N into the k1-th digit of #the top and put x before it and y after it, and then do the Anomalous operation of cancelling #these digits you get a correct thing. Try #Eq(64,10,1,0,x,y); Eq:=proc(N,b,k1,k2,x,y) local N1,n1,d,i1,c1,c2,lu: N1:=convert(N,base,b): if not (k2>=0 and k2<=nops(N1)) then RETURN(FAIL): fi: d:=N1[k2+1]: n1:=add(N1[i1+1]*b^i1,i1=0..k2-1)+add(N1[i1+1]*b^(i1-1),i1=k2+1..nops(N1)-1): if n1=0 then RETURN(FAIL): fi: lu:=numer((x*b^(k1+1)+d*b^k1+y)/N-(x*b^k1+y)/n1): c1:=coeff(lu,x,1): c2:=coeff(lu,y,1): lu:=lu/gcd(c1,c2): lu: end: #OS(L): inputs a list of length 4, [m1,n1,f1,f2] #m1 and n1 are pos. integers m1>n1 and f1 and f2 are expressions #finds q and r such that m1=q*n1+r and returns [n1,r,f2,f1-q*f2]. In other words, #performs one step in the Euclidean algorithm. Try: #OS([17,13,A,B]); OS:=proc(L) local m1,n1,f1,f2,q,r: m1:=L[1]: n1:=L[2]: f1:=L[3]: f2:=L[4]: if m1n and outputs [d,[c1,c2]] #where d=gcd(m,n). c1 and c2 are integers such that gcd(m,n)=c1*m+c2*n. #In other words executes the Extended Euclidean algorithm. Try #EAex11(17,6); EAex11:=proc(m,n) local gu,A,B: if not (m>n and m>0 and n>0) then RETURN(FAIL): fi: gu:=[m,n,A,B]: while gu[2]<>0 do gu:=OS(gu): od: [gu[1],[coeff(gu[3],A),coeff(gu[3],B)]]: end: #EAex1(m,n): inputs two pos. integers and outputs integers c1 and c2 such that #c1*m+c1*n=1. Try #EAex1(19,67); EAex1:=proc(m,n) local gu: if m>n then gu:=EAex11(m,n): if gu[1]<>1 then RETURN(FAIL): else RETURN(gu[2]): fi: elif m1 then RETURN(FAIL): else RETURN([gu[2][2],gu[2][1]]): fi: else RETURN(FAIL): fi: end: #EAex(m,n): inputs two integers and outputs integers c1 and c2 such that #c1*m+c1*n=1. Try #EAex(19,67); EAex:=proc(m,n) local gu,m1,n1: if not (type(m,integer) and type(n,integer) and gcd(m,n)=1) then RETURN(FAIL): fi: m1:=abs(m): n1:=abs(n): gu:=EAex1(m1,n1): if gu=FAIL then RETURN(FAIL): fi: [gu[1]*m1/m,gu[2]*n1/n]: end: #SolEq(M,x,y,t): inputs an affine linear expression M in x,y, with integer coefficients #outputs the parametric solution of M=0 in terms of t. Try #SolEq(2*x-3*y+1,x,y,t); SolEq:=proc(M,x,y,t) local m,n,A,gu: m:=coeff(M,x,1): n:=coeff(M,y,1): if gcd(m,n)<>1 then RETURN(FAIL): fi: A:=expand(m*x+n*y-M): if not type(A,integer) then RETURN(FAIL): fi: gu:=EAex(m,n): if gu=FAIL then RETURN(FAIL): fi: [gu[1]*A+n*t,gu[2]*A-m*t]: end: #CheckCand(P,b,k1,k2): Given a pair of integres P in base b and non-neg. integers k1,k2 #checks that the k1-digit of P[1] (in base b) is the same as the k2-digit of P[2], and #that `canelling' them is correct. Try #CheckCand([16,64],10,0,1); CheckCand:=proc(P,b,k1,k2) local N1,N2,N1a,N2a: N1:=convert(P[1],base,b): N2:=convert(P[2],base,b): if (k1+1>nops(N1) or k2+1>nops(N2)) then RETURN(false): fi: if N1[k1+1]<>N2[k2+1] then RETURN(false): fi: N1a:=[op(1..k1,N1),op(k1+2..nops(N1),N1)]: N2a:=[op(1..k2,N2),op(k2+2..nops(N2),N2)]: if LtoN(N1a,b)/LtoN(N2a,b)<>P[1]/P[2] then RETURN(false): fi: true: end: #AC(N,b,k1,k2): inputs a positive integer,N, (in base b), and k1, k2, non-neg. intgers #outputs the set of integers M such that if, in the fraction M/N, the k2-digit of the denominator and k1-th digit of the #numerator are the same, and cancelling them out gives you something correct. #Try: #AC(99,10,0,1); AC:=proc(N,b,k1,k2) local x,y,gu,i,t,t1,t2,mu,N1,d,ku,muam: N1:=convert(N,base,b): if not (k2>=0 and k2<=nops(N1)) then RETURN(FAIL): fi: d:=N1[k2+1]: gu:=Eq(N,b,k1,k2,x,y): if gu=FAIL then RETURN({}): fi: mu:=SolEq(gu,x,y,t): if mu=FAIL then RETURN({}): fi: t1:=trunc(solve(mu[2],t)): if subs(t=t1,mu[2])<0 then t1:=t1+1: fi: t2:=trunc(solve(mu[2]=b^k1-1,t)): ku:={}: for i from t1 to t2 do if subs(t=i,mu[1])>=0 and subs(t=i,mu[2])>=0 then muam:= b^(k1+1)*subs(t=i,mu[1]) +b^k1*d+subs(t=i,mu[2]): if not type(muam/N,integer) and CheckCand([muam,N],b,k1,k2) then ku:=ku union {muam}: fi: fi: od: ku: end: #AllAC(d,b,k1,k2): The list of lists of pairs [A,B] in base b where B is a d-digit integer in base b and #if you remove the k1-th digit and k2-th digits (that must be the same) #and call the new numbers A',B' then A/B=A'/B'. Try #AllAC(4,10,1,1); AllAC:=proc(d,b,k1,k2) local gu,A,mu,mu1: gu:=[]: for A from b^(d-1)+1 to b^d-1 do mu:=AC(A,b,k1,k2): if mu<>{} then gu:=[op(gu), [seq([mu1,A],mu1 in mu)]]: fi: od: gu: end: #AllACnat(d,b,k1,k2): #The list if lists of pairs [A,B] in base b where B is a d-digit integer in base b and if you remove the k1-th digit and k2-th digits (that must be the same) #and call the new numbers A',B' then A/B=A'/B'. Here the intgeres are represended in base b, but the digits are decimal. Try #AllACnat(4,10,1,1); AllACnat:=proc(d,b,k1,k2) local gu,A,mu,mu1: gu:=[]: for A from b^(d-1)+1 to b^d-1 do mu:=AC(A,b,k1,k2): if mu<>{} then gu:=[op(gu), [seq([CB(mu1,b), CB(A,b)],mu1 in mu)]]: fi: od: gu: end: #ToT(P,b,k1,k2): converts the pair P in base b to a fraction in TeX where the k1-digit of P[1] and k2-digit is crossed-out. #Try: #ToT([457,875],10,0,1); ToT:=proc(P,b,k1,k2) local N1,N2,gu,i,i1,N1a,N2a: N1:=convert(P[1],base,b): N2:=convert(P[2],base,b): N1a:=[op(1..k1,N1),op(k1+2..nops(N1),N1)]: N2a:=[op(1..k2,N2),op(k2+2..nops(N2),N2)]: gu:=`$\\frac{` : for i from nops(N1) to 1 by -1 do i1:= i-1: if i1<>k1 then gu:=cat(gu,Ta1(N1[i])): else gu:=cat(gu,`\\not`): gu:=cat(gu,Ta1(N1[i])): fi: od: gu:=cat(gu,`}{`): for i from nops(N2) to 1 by -1 do i1:= i-1: if i1<>k2 then gu:=cat(gu,Ta1(N2[i])): else gu:=cat(gu,`\\not`): gu:=cat(gu,Ta1(N2[i])): fi: od: gu:=cat(gu,`}=\\frac{` ): for i from nops(N1a) to 1 by -1 do gu:=cat(gu,Ta1(N1a[i])): od: gu:=cat(gu,`}{` ): for i from nops(N2a) to 1 by -1 do i1:= i-1: gu:=cat(gu,Ta1(N2a[i])): od: gu:=cat(gu,`}$`): gu: end: #ToTg(LP,b,k1,k2): converts a list of pairs LP in base b to a fraction in TeX where the k1-digit of P[1] and k2-digit is crossed-out. #Try: #ToTg([[457,875]],10,0,1); ToTg:=proc(LP,b,k1,k2) local N1,N2,gu,i,i1,N1a,N2a,r,P: gu:=`$`: for r from 1 to nops(LP) do P:=LP[r]: N1:=convert(P[1],base,b): N2:=convert(P[2],base,b): N1a:=[op(1..k1,N1),op(k1+2..nops(N1),N1)]: N2a:=[op(1..k2,N2),op(k2+2..nops(N2),N2)]: gu:=cat(gu,`\\frac{`) : for i from nops(N1) to 1 by -1 do i1:= i-1: if i1<>k1 then gu:=cat(gu,Ta1(N1[i])): else gu:=cat(gu,`\\not`): gu:=cat(gu,Ta1(N1[i])): fi: od: gu:=cat(gu,`}{`): for i from nops(N2) to 1 by -1 do i1:= i-1: if i1<>k2 then gu:=cat(gu,Ta1(N2[i])): else gu:=cat(gu,`\\not`): gu:=cat(gu,Ta1(N2[i])): fi: od: gu:=cat(gu,`}=\\frac{` ): for i from nops(N1a) to 1 by -1 do gu:=cat(gu,Ta1(N1a[i])): od: gu:=cat(gu,`}{` ): for i from nops(N2a) to 1 by -1 do i1:= i-1: gu:=cat(gu,Ta1(N2a[i])): od: gu:=cat(gu,`},`): od: gu:=cat(gu,`$`): gu: end: #AllACtexOld(d,b,k1,k2): Like AllAC(d,b,k1,k2): but in TeX #The list if lists of pairs [A,B] in base b where B is a d-digit integer in base b and if you remove the k1-th digit and k2-th digits (that must be the same) #and call the new numbers A',B' then A/B=A'/B'. Try #AllACtexOld(4,10,1,1); AllACtexOld:=proc(d,b,k1,k2) local gu,i1,j1,P: gu:=AllAC(d,b,k1,k2): for i1 from 1 to nops(gu) do for j1 from 1 to nops(gu[i1]) do P:=gu[i1][j1]: print(ToT(P,b,k1,k2)): od: od: end: #AllACtex(d,b,k1,k2): Like AllAC(d,b,k1,k2): but in TeX #The list if lists of pairs [A,B] in base b where B is a d-digit integer in base b and if you remove the k1-th digit and k2-th digits (that must be the same) #and call the new numbers A',B' then A/B=A'/B'. Try #AllACtex(4,10,1,1); AllACtex:=proc(d,b,k1,k2) local gu,i1,j1: gu:=AllAC(d,b,k1,k2): for i1 from 1 to nops(gu) do print(seq(ToT(gu[i1][j1],b,k1,k2),j1=1..nops(gu[i1]) )): od: end: #AllACtexV(d,b,k1,k2): Like AllACtex(d,b,k1,k2): but Verbosely. Try: #AllACtexV(4,10,1,1); AllACtexV:=proc(d,b,k1,k2) local gu,i1,j1: gu:=AllAC(d,b,k1,k2): if b<>10 then print(`All the Anomalous Cancellations in base b with the denominator with`, d, `digits, and where the `, k1, `-th digit of the numerator`): print(`is cancelled out with the`, k2,` -th digit of the denominator`): else print(`All the Anomalous Cancellations with the denominator with`, d, `digits, and where the `, k1, `-th digit of the numerator`): print(`is cancelled out with the`, k2,` -th digit of the denominator`): fi: for i1 from 1 to nops(gu) do printf("denominator= %g\n", gu[i1][1][2] ); print(``): for j1 from 1 to nops(gu[i1]) do print(ToT(gu[i1][j1],b,k1,k2)): od: print(``): od: print(`-------------------------------------------------------------------------`): end: #BookACtex(Maxd,b): inputs a positive integer Maxd, and a base b, and outputs a book with all the anomalous cancellations in base b #with denominators that are between 2-digit to Maxd diegits. Try: #BookACtex(3,10); BookACtex:=proc(Maxd,b) local k1, k2,d,c1,s1,t0: t0:=time(): if b<>10 then print(`Lots and Lots of Anomalous Cancellations in base`, b) else print(`Lots and Lots of Anomalous Cancellations `) fi: print(`By Shalosh B. Ekhad `): if b<>10 then print(`In this book, you will find listed all the anomalous cancellations in base`, b, `where the denominator has up to `, Maxd, `digits` ): print(`and one digit in the numerator and one in the denominator, that must be the same, gets cancelled, and you still get something correct!`): else print(`In this book, you will find listed all the anomalous cancellation where the denominator has up to `, Maxd , `digits `): print(`and one digit in the numerator and one in the denominator, that must be the same, gets cancelled, and you still get something correct1`): fi: c1:=0: for d from 2 to Maxd do c1:=c1+1: printf("Chapter %g : The denominator has %g digits", c1,d): print(``): s1:=0: for k2 from 0 to d-1 do for k1 from 1 to d-1 do s1:=s1+1: print(``): printf("Section %g",s1 ): print(``): AllACtexV(d,b,k1,k2): od: od: od: print(`This ends this book that took`, time()-t0, `seconds to generate. `): end: #AllACv(d,b,k1,k2): Verbose form of AllAC(d,b,k1,k2). Try: #AllACv(3,10,1,1); AllACv:=proc(d,b,k1,k2) local gu,i1,j1: gu:=AllAC(d,b,k1,k2): if gu={} then RETURN({}): fi: if b<>10 then print(`All the Anomalous Cancellations in base`, b, `with the denominator with`, d, `digits, and where the `, k1, `-th digit of the numerator`): print(`is cancelled out with the`, k2,` -th digit of the denominator`): else print(`All the Anomalous Cancellations with the denominator with`, d, `digits, and where the `, k1, `-th digit of the numerator`): print(`is cancelled out with the`, k2,` -th digit of the denominator`): fi: for i1 from 1 to nops(gu) do printf("denominator= %g\n", gu[i1][1][2] ); print(`numerators:` , seq(gu[i1][j1][1],j1=1..nops(gu[i1]) ) ): print(``): od: print(`-------------------------------------------------------------------------`): end: #AllACvNat(d,b,k1,k2): Verbose form of AllAC(d,b,k1,k2). Try: #AllACvNat(3,12,1,1); AllACvNat:=proc(d,b,k1,k2) local gu,i1,j1: gu:=AllACnat(d,b,k1,k2): if b=10 then RETURN(FAIL): fi: if gu={} then RETURN({}): fi: print(`All the Anomalous Cancellations in base`, b, `with the denominator with`, d, `digits, and where the `, k1, `-th digit of the numerator`): print(`is cancelled out with the`, k2,` -th digit of the denominator`): for i1 from 1 to nops(gu) do print(`denominator=`, gu[i1][1][2] ); for j1 from 1 to nops(gu[i1]) do print( DisFra( [gu[i1][j1][1],gu[i1][1][2]],nops(gu[i1][j1][1])-k1, nops(gu[i1][1][2])-k2) ): od: print(``): od: print(`-------------------------------------------------------------------------`): end: #BookAC(Maxd,b): inputs a positive integer Maxd, and a base b, and outputs a book with all the anomalous cancellations in base b #with denominators that are between 2-digit to Maxd diegits. Try: #BookAC(3,10); BookAC:=proc(Maxd,b) local k1, k2,d,c1,s1,t0: t0:=time(): if b<>10 then print(`Lots and Lots of Anomalous Cancellations in base`, b) else print(`Lots and Lots of Anomalous Cancellations `) fi: print(`By Shalosh B. Ekhad `): if b<>10 then print(`In this book, you will find listed all the anomalous cancellations in base`, b, `where the denominator has up to `, Maxd, `digits` ): print(`and one digit in the numerator and one in the denominator, that must be the same, gets cancelled, and you still get something correct!`): else print(`In this book, you will find listed all the anomalous cancellation where the denominator has up to `, Maxd , `digits `): print(`and one digit in the numerator and one in the denominator, that must be the same, gets cancelled, and you still get something correct1`): fi: c1:=0: for d from 2 to Maxd do c1:=c1+1: printf("Chapter %g : The denominator has %g digits", c1,d): print(``): s1:=0: for k2 from 0 to d-1 do for k1 from 0 to d-1 do if AllAC(d,b,k1,k2)<>{} then s1:=s1+1: print(``): printf("Section %g",s1 ): print(``): AllACv(d,b,k1,k2): fi: od: od: od: print(`This ends this book that took`, time()-t0, `seconds to generate. `): end: #BookACnat(Maxd,b): inputs a positive integer Maxd, and a base b, and outputs a book with all the anomalous cancellations in base b #with denominators that are between 2-digit to Maxd diegits. Try: #BookACnat(3,14); BookACnat:=proc(Maxd,b) local k1, k2,d,c1,s1,t0: t0:=time(): if b=10 then BookAC(Maxd,10): RETURN(): fi: print(`Lots and Lots of Anomalous Cancellations in base`, b): print(`By Shalosh B. Ekhad `): print(`In this book, you will find listed all the anomalous cancellations in base`, b, `where the denominator has up to `, Maxd, `digits` ): print(`and one digit in the numerator and one in the denominator, that must be the same, gets cancelled, and you still get something correct!`): c1:=0: for d from 2 to Maxd do c1:=c1+1: printf("Chapter %g : The denominator has %g digits", c1,d): print(``): s1:=0: for k2 from 0 to d-1 do for k1 from 0 to d-1 do if nops(AllAC(d,b,k1,k2))>0 then s1:=s1+1: print(``): printf("Section %g",s1 ): print(``): AllACvNat(d,b,k1,k2): fi: od: od: od: print(`This ends this book that took`, time()-t0, `seconds to generate. `): end: #DisFra(L,i,j): inputs a pair of lists L, and integers i and j such that i is between 1 and nops(L[1]) and #j is between 1 and nops(L[2]) displays the cancellation L[1]/L[2], where i-th item is removed from #L[1] and the j-th from L[2]. Try: #DisFra([[1,2,3],[3,2,5]],2,2); DisFra:=proc(L,i,j) local L1,L2,L1a,L2a: L1:=L[1]: L2:=L[2]: if not (1<=i and i<=nops(L1) and 1<=j and j<=nops(L2)) then RETURN(FAIL): fi: L1a:=[op(1..i-1,L1),op(i+1..nops(L1),L1)]: L2a:=[op(1..j-1,L2),op(j+1..nops(L2),L2)]: L1/L2 = L1a/L2a: end: #Boas(B): All the anaomalous cancellations with 2 digits where the unit digit at the bottom cancells out with the "ten" digit of the top #for all bases up to B that are non-empty. It extens the tables on pp. 119-122 in R.P. Boas' beautiful article #"Anomalos Cancellation", in: "Mathematical Plums", Ross Honsberger, ed., Math. Assoc. of Amer., 1979 #Try: #Boas(100); Boas:=proc(B) local b,gu: for b from 2 to B do gu:=AllAC(2,b,0,1): if nops(gu)>0 then print(`base=`, b, `Number of Solutions=`, nops(gu)): print(``): AllACvNat(2,b,0,1): fi: od: end: