flat assembler
Message board for the users of flat assembler. Index > Heap > What is the best pie you can get with 9 digits? Goto page Previous  1, 2, 3 ... 24, 25, 26, 27, 28, 29  Next
Author
 Thread  YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG Tomasz Grysztar wrote:I used a simple expression generator (on top of a digit permutation) and fasmg's "eval" to find the above ones. See if you can find an expression for each of these numbers with your program: 42722830 -- using seven digits, from 1 to 7 I believe this one is doable because I have already worked out a very close value by hand: (5^6 + 1) x 2734 = 42721484 But I need the exact value. The pi approximation will be correct to 7 decimal places! 888582403 -- using six digits, either {2, 4, 5, 7, 8, 9} or {3, 4, 5, 6, 7, 8} This one may not be doable. Still, give it a try. The pi approximation will be correct to 10 decimal places! I am happy to share the honors with you! Please bring me some good news on New Year Day!  31 Dec 2016, 12:23
 bitRAKE Joined: 21 Jul 2003 Posts: 2913 Location: [RSP+8*5] bitRAKE 3-(51-67)/(24+89) another in the set of 6 correct places, lol. There are a lot of possible patterns. 02 Jan 2017, 03:37
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG So, the best answers as of now are still correct to 6 decimal places: T.G.: (2+6*9/743)*8^(1/5) = 3.14159288348 ... bitRAKE: 3-(51-67)/(24+89) = 3.14159292035 ... Come on! Something even better is out there!  02 Jan 2017, 04:06
 bitRAKE Joined: 21 Jul 2003 Posts: 2913 Location: [RSP+8*5] bitRAKE The power searches take a long time... Three) 3+4^6^1/(7^2*589) I can search any pattern you think might be fruitful. _________________¯\(°_o)/¯ unlicense.org 02 Jan 2017, 05:05
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG bitRAKE wrote:3+4^6^1/(7^2*589) Just correct to 3 decimal places. Not good enough by the 2017 standard! bitRAKE wrote:I can search any pattern you think might be fruitful. Then try this one: 42722830 -- using seven digits, from 1 to 7 I need the exact value. The pi approximation will be correct to 7 decimal places! Thanks!  02 Jan 2017, 05:22
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG Just found one, which has the same value as 355/113: 3^1 + (4^2)/((9+5)*8 + 7 - 6) = 3.14159292035 ... Still correct to 6 decimal places.  02 Jan 2017, 07:41
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG So, the best answers as of now are still correct to 6 decimal places: T.G.: (2+6*9/743)*8^(1/5) = 3.14159288348 ... bitRAKE: 3-(51-67)/(24+89) = 3.14159292035 ... YONG: 3^1 + (4^2)/((9+5)*8 + 7 - 6) = 3.14159292035 ... Come on! Something even better is out there! 02 Jan 2017, 07:43
 Tomasz Grysztar Assembly Artist Joined: 16 Jun 2003 Posts: 7720 Location: Kraków, Poland Tomasz Grysztar My simple "eval" script was able to search only through specific types of expressions, so to give it a try I wrote a proof-of-concept script in fasmg that does a brute force search through all possible expressions in RPN notation: Code:```aim = 3.141592653589793238462643383279502884197169399375105820974 delta = 1 ; start showing results when they are within this distance from the aim digits db '1234' digits_count = \$-digits operators db '+-*/^' operators_count = \$-operators ln2 = 0.693147180559945309417232121458176568075500134360255254120 while 1 repeat 1 shl (digits_count-1), separators:0 ; Create numbers from digits: position = 0 repeat digits_count, index:0 load digit:byte from digits+position position = position + 1 number#index = digit-'0' while separators shr (position-1) and 1 load digit:byte from digits+position position = position + 1 number#index = number#index*10 + digit-'0' end while if position >= digits_count numbers_count = % break end if end repeat variations_count = 1 repeat numbers_count-1 variations_count = variations_count*operators_count end repeat repeat variations_count, variation:0 ; Prepare distribution of operators: operators_count0 = 0 counter = numbers_count-1 while 1 repeat counter operators_count#% = 1 end repeat ; Evaluate: variation_cursor = variation repeat numbers_count, index:0 stack =: number#index repeat operators_count#index tmp = stack restore stack operator_index = variation_cursor mod operators_count variation_cursor = variation_cursor / operators_count load operator:1 from operators+operator_index if operator = '+' stack = stack + tmp else if operator = '-' stack = stack - tmp else if operator = '*' stack = stack * tmp else if operator = '/' stack = float stack / tmp else if operator = '^' if tmp < 20 & tmp > -20 & tmp = trunc tmp tmp = trunc tmp inv = 0 if tmp < 0 inv = 1 tmp = -tmp end if sq = stack stack = 1 while tmp if tmp and 1 stack = stack * sq end if sq = sq * sq tmp = tmp shr 1 end while if inv stack = float 1/stack end if else x = float stack if x > 0 ln = 2*(x-1)/(x+1) repeat 4 k = trunc (ln/ln2) r = ln - k*ln2 term = 1 exp = term repeat 12 term = term*r/(float %) exp = exp + term end repeat exp = exp shl k ln = ln + 2*(x-exp)/(x+exp) end repeat x = ln*tmp k = trunc (x/ln2) r = x - k*ln2 term = 1 stack = term repeat 12 term = term*r/(float %) stack = stack + term end repeat stack = stack shl k else stack = 0 end if end if else err 'unknown operator' end if end repeat end repeat result = stack restore stack d = result-aim if (d > 0 & d < delta) | (d < 0 & d > -delta) if d > 0 delta = d else delta = -d end if ; Display generated expression: variation_cursor = variation repeat numbers_count, index:0 if % > 1 display ' ' end if repeat 1, x: number#index display `x end repeat repeat operators_count#index operator_index = variation_cursor mod operators_count variation_cursor = variation_cursor / operators_count load operator:1 from operators+operator_index display ' ',operator end repeat end repeat out showfloat result display ' = ',out,13,10 end if ; Next distribution of operators: counter = -1 repeat numbers_count-1, index:0 if operators_count#index > 0 operators_count#% = operators_count#% + 1 counter = operators_count#index - 1 operators_count#index = 0 break end if end repeat if counter < 0 break end if end while end repeat end repeat ; Next permutation of digits: i = digits_count-1 while i >= 0 load b:byte from digits+i i = i - 1 if i >= 0 load a:byte from digits+i if a < b break end if end if end while if i < 0 break end if j = i + 1 while j < digits_count-1 load c:byte from digits+j+1 if c > a b = c j = j + 1 else break end if end while store b:byte at digits+i store a:byte at digits+j i = i + 1 j = digits_count-1 while i < j load x:byte from digits+i load y:byte from digits+j store x:byte at digits+j store y:byte at digits+i i = i + 1 j = j - 1 end while end while ```As you can see, I set up the sample above so that it searches through expressions composed from digits 1-4 only. It gets very slow quickly for larger sets of digits (to monitor the script I made a tweaked version of fasmg that shows the messages generated with DISPLAY immediately instead of buffering them*). The next step should be to rewrite this prototype script in assembly, though I do not have time for this now. With a native implementation exhaustive search through expressions generated from a sets of 6 or even 7 digits may be doable. But 8 and more is probably going to be unattainable with this method. (The script uses the "showfloat" macro I once shared in the other thread.) Some interesting results from my test searches with small sets of digits: with digits 1-4 the best possible approximation of pi is 3+2/14 = 3.1428571429..., interestingly digits 1-5 yield no better result. For a set of digits 1-6 some better results start coming in, for example 1*(35-4)^(2/6)=3.141380652... but I have not yet finished this search. YONG wrote:See if you can find an expression for each of these numbers with your program: (...) With this script I can now try to search through expressions generated with 6 digits. With a native implementation perhaps the exhaustive search with 7 digits would also be possible. ___ * This is now in the official fasmg releases as a hidden "-v2" option. Last edited by Tomasz Grysztar on 08 Sep 2017, 17:04; edited 9 times in total 02 Jan 2017, 09:38
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG Am I dreaming? How come the above script -- written by T.G. -- actually has some comments?  02 Jan 2017, 11:49
 Tomasz Grysztar Assembly Artist Joined: 16 Jun 2003 Posts: 7720 Location: Kraków, Poland Tomasz Grysztar And another bug in fasmg found thanks to these scripts...  02 Jan 2017, 15:26
 bitRAKE Joined: 21 Jul 2003 Posts: 2913 Location: [RSP+8*5] bitRAKE Code:```5) 296^5/(81-4)^7+3 (278^4+-1)/59^6+3 (6/8)^5 * (3/9)^1 * (7/4)^2 [6^(4-3)+7^(9-2)]/8^(1+5) ```...some lesser solutions. 02 Jan 2017, 18:53
 bitRAKE Joined: 21 Jul 2003 Posts: 2913 Location: [RSP+8*5] bitRAKE Tomasz Grysztar wrote:And another bug in fasmg found thanks to these scripts... Does it also cover multiple operators? Specifically, A*-B comes to mind. I was thinking "-/" could be replaced by a monotonic negation - actually, I think it's called something else. Where each value can be subtracted from zero by itself. This probably increases the complexity rather than the intent. I like how you choose to iterate between the operators - very concise. _________________¯\(°_o)/¯ unlicense.org 02 Jan 2017, 19:58
 Tomasz Grysztar Assembly Artist Joined: 16 Jun 2003 Posts: 7720 Location: Kraków, Poland Tomasz Grysztar bitRAKE wrote: Tomasz Grysztar wrote:And another bug in fasmg found thanks to these scripts... Does it also cover multiple operators? Specifically, A*-B comes to mind. I was thinking "-/" could be replaced by a monotonic negation - actually, I think it's called something else. Where each value can be subtracted from zero by itself. This probably increases the complexity rather than the intent. I like how you choose to iterate between the operators - very concise. My implementation does not have unary operators. You could insert any number of unary operators in any place in a RPN expression. For unary minus it does not make sense to put more than one in a row anywhere, but for example if we had allowed square root (which is also an unary operator), the number of potential expressions would become infinite. Whether the formulation of problem allows to unary minus is another issue. This probably should be clarified. 02 Jan 2017, 20:06
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG Tomasz Grysztar wrote:but for example if we had allowed square root (which is also an unary operator) ... Whether the formulation of problem allows to unary minus is another issue. This probably should be clarified. Allowing square root means freeing up at least two digits: ^(1/2) becomes √ Allowing the radical sign of the higher roots means freeing up at least one digit: ^(1/n) becomes ^n √ Allowing unary minus in the power means freeing up at least one digit: (1/x)^n becomes x^(-n) A wise forum member once said, "Something something keeping up the standards something something." So, I would say we better stick to those restrictive rules and maintain the difficulty of the problem.  03 Jan 2017, 03:48
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG bitRAKE wrote: Code:```5) 296^5/(81-4)^7+3 (278^4+-1)/59^6+3 (6/8)^5 * (3/9)^1 * (7/4)^2 [6^(4-3)+7^(9-2)]/8^(1+5) ```...some lesser solutions. In (278^4+-1)/59^6+3, there is no need to write "+-1". Just write "-1". The expression ( 6 / 8 )^5 * (3/9)^1 * (7/4)^2 gives 0.24224853515. Something is wrong with your program.  03 Jan 2017, 03:57
 Tomasz Grysztar Assembly Artist Joined: 16 Jun 2003 Posts: 7720 Location: Kraków, Poland Tomasz Grysztar YONG wrote:888582403 -- using six digits, either {2, 4, 5, 7, 8, 9} or {3, 4, 5, 6, 7, 8} This one may not be doable. Still, give it a try. I've been running my fasmg script in the background searching with these two sets of digits, but as you suspected no expression yielded such result. The closest number that it found is: Code:`[RPN] 5 2 * 9 4 78 / - ^ = (5*2)^(9-(4/78)) = 888623816.274... ` If we raise this to the power 1/(3*6), which is what I suspect you wanted to do, we get an approximation of pi, but it is much worse than the ones we already have: Code:`((5*2)^(9-(4/78)))^(1/(3*6)) = 3.1416007876788536... ` The search for 42722830 that you also asked for is practically out of reach with fasmg script, because the number of expressions for seven digits is much larger. But I we write a native implementation of the searcher, then such search may become possible. But brute force scans with 8 and 9 digits are going to be out of reach anyway. 05 Jan 2017, 09:12
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG @T.G.: Thank you very much. So, six digits is basically the limit for your script. Then give the following a try: 924269 -- using six digits: {2, 5, 6, 7, 8, 9}, {3, 4, 5, 7, 8, 9}, {2, 4, 5, 6, 7, 8}, {2, 3, 5, 6, 7, 9}, or {2, 3, 4, 6, 8, 9}. (924269)^(1/(3*4)) = (924269)^(1/(2*6)) = (924269)^(1/(3+9)) = (924269)^(1/( 4 + 8 )) = (924269)^(1/(5+7)) = 3.14159260217 ... (correct to 7 decimal places) If I can use one more digit (4), here is the solution: (6^3 * 4279 + 5)^(1/(8+4)) = 924269^(1/12) = 3.14159260217 ... Please give me some good news this time!  05 Jan 2017, 10:20
 Tomasz Grysztar Assembly Artist Joined: 16 Jun 2003 Posts: 7720 Location: Kraków, Poland Tomasz Grysztar I have continued to look for 888582403 with other sets of digits, because there are also other ways to make 1/18 power. And I found this one: Code:`[RPN]41 5 ^ 9 7 ^ - 8 * = (41^5-9^7)*8 = 888585856 `Still not perfect, but a bit better, and the pi approximation it gives is: Code:`((41^5-9^7)*8)^(2/36)=3.14159333180... ` 05 Jan 2017, 13:56
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG Tomasz Grysztar wrote:there are also other ways to make 1/18 power Good point! 1/12 = 2/24 = 2/( 3 * 8 ) = 2/(4*6) = 4/48 = 4/( 6 * 8 ) = 8/96 So, please also try: {1, 4, 5, 6, 7, 9}, {1, 3, 5, 7, 8, 9}, {1, 2, 3, 5, 7, 9}, and {1, 2, 3, 4, 5, 7} for 924269. Thanks!  06 Jan 2017, 01:33
 YONG Joined: 16 Mar 2005 Posts: 8000 Location: 22° 15' N | 114° 10' E YONG Any number n within the range 888582131 =< n =< 888582639 can give a pi approximation correct to 7 (or more) decimal places. Come on!  06 Jan 2017, 04:57
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First  Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsCompiler InternalsIDE DevelopmentOS ConstructionNon-x86 architecturesHigh Level LanguagesProgramming Language DesignProjects and IdeasExamples and Tutorials Other----------------FeedbackHeapTest Area
Goto page Previous  1, 2, 3 ... 24, 25, 26, 27, 28, 29  Next

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou can attach files in this forumYou can download files in this forum