From israel@math.ubc.ca Thu May 11 18:41:06 CDT 2006 Article: 472350 of sci.math Path: news!news.niu.edu!canoe.uoregon.edu!elk.ncren.net!newsflash.concordia.ca!cs.ubc.ca!nntp.itservices.ubc.ca!not-for-mail From: israel@math.ubc.ca (Robert Israel) Newsgroups: sci.math Subject: Re: I have the numbers, I need an equation ... site or app to do this? Date: 10 May 2006 06:29:41 GMT Organization: ITServices, University of British Columbia Lines: 94 Message-ID: References: X-Trace: nntp.itservices.ubc.ca 1147242581 26363 137.82.36.63 (10 May 2006 06:29:41 GMT) X-Complaints-To: abuse@interchange.ubc.ca X-Newsreader: trn 4.0-test72 (19 April 1999) Xref: news sci.math:472350 In article , H.B. Elkins wrote: >Greetings, sci.math folks. > >I am in need of a way to take a set of numbers and come up with an equation >using all those numbers. > >For instance, if I have 1, 7 and 64, I can get 1 + 7 = (sqrt) 64. > >If I have 3, 3 and 12, I can get 3! + 3! = 12. > >If I have 2, 7 and 9, I can get 2 + 7 = 9. > >And if I have 2, 9, 13, 14 and 16, I can get (16-14) + 2 = 13 - 9. > >Or if I have 2, 11, 11 (yes, using 11 twice) and 33, I can get 33 - 11 = 2 x 11, >or even 33 - (2x11) = 11. > >Is there a Web site somewhere, or an application (PC or Mac), that will take a >set of numbers I throw at it and give me an equation? > >Any and all help appreciated -- if you prefer not to post here, I can be emailed >at hbelkins(at)mis.net. > >Many thanks and my undying gratitude for a solution! Suppose you want to allow +, -, *, /, sqrt and ! (but with / and sqrt only when results will be integers, and ! only for integers between 2 and 10). Here's a Maple program that will take a set S of integers and return a set of pairs [m,e] where m is a result obtained from S using the expression e. F:= proc(S::set(integer)) local R,s,sn,Res,Res2, Res3, n; s:= S[1]; R:= S minus {s}; sn:= convert(s,name); Res:= [s,sn]; if s > 1 and s <= 10 then Res:= Res,[s!, sn!] fi; if s <> 0 then Res:= Res,[-s, -sn] fi; if s > 1 and type(sqrt(s),integer) then Res:= Res, [sqrt(s),sqrt(sn)] fi; Res:= [Res]; if R = {} then return Res fi; Res2:= F(R); Res:= select(p -> type(p[1],integer), [seq(seq(A+B,A=Res),B=Res2), seq(seq([A[1]*B[1],A[2]*B[2]],A=Res),B=Res2), seq(seq([A[1]/B[1],A[2]/B[2]],A=Res),B=Res2), seq(seq([B[1]/A[1],B[2]/A[2]],A=Res),B=Res2)]); Res:= [op(Res), op(map(t -> [sqrt(t[1]),sqrt(t[2])], select(t -> type(sqrt(t[1]),integer), Res)))]; Res:= [op(Res), op(map(t -> [t[1]!, t[2]!], select(t -> (t[1] > 1 and t[1] <= 10), Res)))]; Res:= sort(Res, (a,b) -> (abs(a[1]+1/3) Res[n][1], Res[n],NULL),n=1..nops(Res))] end; And here is a Maple procedure, using this, that takes two sets of integers and (if it can) prints equations using the numbers in the first set on the left and the numbers in the second set on the right. Idents:= proc(S1::set(integer),S2::set(integer)) local Res1,Res2,L,v,e1,e2; Res1:= F(S1); Res2:= F(S2); L:= convert(map2(op,1,Res1),set) intersect convert(map2(op,1,Res2),set); if L = {} then print("No Solution") else for v in L do print( op(select(t -> (t[1]=v), Res1))[2] = op(select(t -> (t[1]=v), Res2))[2]) od fi end; For example: > Idents({23, 43, 52, 56}, {25, 60, 90, 93}); -`56`-`52`+`43`-`23` = -`93`+`90`-`60`-`25` (((`56`-`52`)!-`43`+`23`)^(1/2))! = ((`60`/(`93`-`90`)/`25`^(1/2))^(1/2))! (-`56`+`52`+`43`-`23`)^(1/2) = `60`/(`93`-`90`)/`25`^(1/2) ((-`56`+`52`+`43`-`23`)^(1/2))! = (`60`/(`93`-`90`)/`25`^(1/2))! -`56`+`52`+`43`+`23` = -`93`+`90`+`60`+`25`^(1/2) ((`56`-`52`)^(1/2))!+`43`+`23` = `93`-`90`+`60`+`25`^(1/2) `56`+`52`-`43`+`23` = `93`-`90`+`60`+`25` `56`+`52`+`43`-`23` = `93`+`90`-`60`+`25`^(1/2) Note: ^(1/2) is used instead of sqrt; ignore the `` quotes, which turn numbers into symbols to prevent Maple from doing arithmetic with them. Robert Israel israel@math.ubc.ca Department of Mathematics http://www.math.ubc.ca/~israel University of British Columbia Vancouver, BC, Canada