Engel expansion: Difference between revisions

m
→‎{{header|Phix}}: removed the 70 limit now improves the p2js output
m (→‎{{header|Phix}}: changed dp from 180 to 134 (min rqd))
m (→‎{{header|Phix}}: removed the 70 limit now improves the p2js output)
Line 104:
<span style="color: #004080;">mpfr</span> <span style="color: #000000;">u</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpfr_init</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">a</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpfr_init</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">mpfr_cmp_si</span><span style="color: #0000FF;">(</span><span style="color: #000000;">u</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">and</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">engel</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">70</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">mpfr_si_div</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">u</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">mpfr_ceil</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)</span>
Line 155 ⟶ 154:
{{out}}
I could only get pi accurate to 125 decimal places and root2 to 87, so cut the input strings accordingly.<br>
In fact the 1 digit error on desktop/Phix (below) don't happen in a browser. <br>
Increasing the precision helps but only up to a (relatively small) point, ie that 134 ''is'' needed, nowt greater helps at all. <br>
You may or may not have better luck with completely rewriting this to use mpq (rationals).<br>
In fact it works slightly better in a browser (which uses rationals behind the scenes) than on desktop/Phix, as shown below. <br>
<pre>
Rational number : 3.14159265358979
Engel expansion : 1 1 1 8 8 17 19 300 1991 2768 4442 4830 10560 37132 107315 244141 651042 1953125 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647
Number of terms : 7083, places : 14 (14 correct)
Back to rational: 3.14159265358979
 
Rational number : 2.71828182845904
Engel expansion : 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 82 144 321 2289 9041 21083 474060 887785 976563 1953125 2147483647 2147483647 2147483647
Number of terms : 70101, places : 14 (14 correct)
Back to rational: 2.71828182845904
 
Rational number : 1.414213562373095
Engel expansion : 1 3 5 5 16 18 78 102 120 144 260 968 18531 46065 63005 65105 78125 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647
Number of terms : 7067, places : 15 (15 correct)
Back to rational: 1.414213562373095
 
Line 181 ⟶ 180:
Rational number : 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384
Engel expansion : 1 1 1 8 8 17 19 300 1991 2492 7236 10586 34588 63403 70637 1236467 5417668 5515697 5633167 7458122 9637848 9805775 41840855 58408380 213130873 424342175 2147483647 2147483647 2147483647 2147483647
Number of terms : 70181, places : 125 (125 correct)
Back to rational: 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384
 
Rational number : 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642743
Engel expansion : 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Number of terms : 70222, places : 101 (100101 correct)
Back to rational: 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642743
Back to rational: 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742
 
Rational number : 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387
Engel expansion : 1 3 5 5 16 18 78 102 120 144 251 363 1402 31169 88630 184655 259252 298770 4196070 38538874 616984563 1975413038 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647
Number of terms : 70175, places : 87 (87 correct)
Back to rational: 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387
 
Rational number : 25.628906
Engel expansion : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 4 33 33 35
Number of terms : 5465, places : 6 (6 correct)
Back to rational: 25.628906
</pre>
Output under p2js:
<pre>
Rational number : 3.14159265358979
Engel expansion : 1 1 1 8 8 17 19 300 1991 2768 4442 4830 10560 37132 107315 244141 651042 1953125
Number of terms : 18, places : 14 (14 correct)
Back to rational: 3.14159265358979
 
Rational number : 2.71828182845904
Engel expansion : 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 82 144 321 2289 9041 21083 474060 887785 976563 1953125
Number of terms : 27, places : 14 (14 correct)
Back to rational: 2.71828182845904
 
Rational number : 1.414213562373095
Engel expansion : 1 3 5 5 16 18 78 102 120 144 260 968 18531 46065 63005 65105 78125
Number of terms : 17, places : 15 (15 correct)
Back to rational: 1.414213562373095
 
Rational number : 7.59375
Engel expansion : 1 1 1 1 1 1 1 2 6 8
Number of terms : 10, places : 5 (5 correct)
Back to rational: 7.59375
 
Rational number : 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384
Engel expansion : 1 1 1 8 8 17 19 300 1991 2492 7236 10586 34588 63403 70637 1236467 5417668 5515697 5633167 7458122 9637848 9805775 41840855 58408380 213130873 424342175 2717375531 323878055376 339280401894 386771504748
Number of terms : 161, places : 125 (125 correct)
Back to rational: 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384
 
Rational number : 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642743
Engel expansion : 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Number of terms : 150, places : 101 (101 correct)
Back to rational: 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642743
 
Rational number : 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387
Engel expansion : 1 3 5 5 16 18 78 102 120 144 251 363 1402 31169 88630 184655 259252 298770 4196070 38538874 616984563 1975413038 7855284583 34680535992 47012263568 82957997141 1709576125547 42630379527673 164312229775505 404736776022426
Number of terms : 110, places : 87 (87 correct)
Back to rational: 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387
 
Rational number : 25.628906
Engel expansion : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 4 33 33 35
Number of terms : 34, places : 6 (6 correct)
Back to rational: 25.628906
</pre>
 
7,794

edits