Skip to content

Commit

Permalink
Added scripts to compute pi with 33331 digits
Browse files Browse the repository at this point in the history
  • Loading branch information
alpertron committed May 24, 2024
1 parent b1e4828 commit 6d26a59
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ConsoleApplication1.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>11 11 10 121</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>"x=0;x=x+(2^(110742-c*4)/(8*(c-1)+1)-2^(110741-c*4)/(8*(c-1)+4)-2^(110740-c*4)/(8*(c-1)+5)-2^(110740-c*4)/(8*(c-1)+6));c&lt;=27674;x*10^33330/2^110736;c==27674" 4 0</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommand>$(TargetPath)</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>$(ProjectDir)\x64\release</LocalDebuggerWorkingDirectory>
Expand Down
5 changes: 5 additions & 0 deletions ECM.HTM
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,11 @@ The line to type is: <code>x=1;x=x+1;x&lt;10000;x;sumdigits(x, 10)==sumdigits(co
<p>To print a percent sign, you have to write two percent signs, and a quote is represented by a percent sign followed by a quote.</p>
<p>Example 3: For each number between -100 and 100, show whether the number is prime and then show the factorization both in decimal and hexadecimal.</p>
<p>The line to write is: <code>x=-100; x=x+1; x&lt;=100; &quot;%d is prime: %l, %Fd, %Fx&quot;:x:isprime(x):x:x</code>
<p>Example 4: Get 33331 digits of &pi; using Gauss-Legendre algorithm.</p>
<p><code>x=10^99999+10^66666/4+10^66666/sqrt(2*10^66666);x=(x/10^66666+x%10^33333)/2*10^66666+(((x/10^33333)%10^33333)-2^(c-1)*(x/10^66666-(x/10^66666+x%10^33333)/2)^2/10^33333)*10^33333+sqrt((x/10^66666)*(x%10^33333));c&lt;=15;(x/10^66666+x%10^33333)^2/4/((x/10^33333)%10^33333)/1000;c==15</code></p>
<p>In this script written by Samuel Eraut: <var>b</var> = lowest 33333 digits of <var>x</var>, <var>t</var> = next higher 33333 digits, <var>a</var> = all higher digits of <var>x</var>. Variable names <var>a</var>, <var>b</var> and <var>t</var> conform to the current example shown on Gauss-Legendre algorithm on Wikipedia.</p>
<p>Example 5: Get 33331 digits of &pi; using Bailey–Borwein–Plouffe (BBP) formula (script written by Samuel Eraut).</p>
<p><code>x=0;x=x+(2^(110742-c*4)/(8*(c-1)+1)-2^(110741-c*4)/(8*(c-1)+4)-2^(110740-c*4)/(8*(c-1)+5)-2^(110740-c*4)/(8*(c-1)+6));c&lt;=27674;x*10^33330/2^110736;c==27674</code></p>
</div>
<div class="noand">
<h2><button type="button">Source code</button></h2>
Expand Down
6 changes: 6 additions & 0 deletions ECMC.HTM
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ button:disabled {color: #808080; background-color: #606060}
</table>
<p>Puedes usar el prefijo <em>0x</em> para números hexadecimales, por ejemplo 0x38 es igual a 56.</p>
</div>

<h2><button type="button">Factorización usando el método de curvas elípticas (ECM)</button></h2>
<div class="panel">
<p>La notación <var>k</var> &equiv; <var>m</var> (mod <var>n</var>) significa que el resto de la división de <var>k</var> dividido <var>n</var> es igual al resto de la división de <var>m</var> dividido <var>n</var>. El número <var>n</var> se denomina módulo.</p>
Expand Down Expand Up @@ -1003,6 +1004,11 @@ La línea a escribir es: <code>x=1;x=x+1;x&lt;10000;x;sumdigits(x, 10)==sumdigit
<p>Para mostrar el símbolo de procentaje, se deben usar dos símbolos de porcentaje seguidos, y la comilla se representa mediante un símbolo de porcentaje seguido por una comilla.</p>
<p>Ejemplo 3: Por cada número entre -100 y 100, mostrar si el número es primo y luego mostrar la factorización tanto en decimal como en hexadecimal.</p>
<p>La línea a escribir es: <code>x=-100; x=x+1; x&lt;=100; &quot;%d es primo: %l, %Fd, %Fx&quot;:x:isprime(x):x:x</code>
<p>Ejemplo 4: Obtener 33331 dígitos de &pi; usando el algoritmo de Gauss-Legendre.</p>
<p><code>x=10^99999+10^66666/4+10^66666/sqrt(2*10^66666);x=(x/10^66666+x%10^33333)/2*10^66666+(((x/10^33333)%10^33333)-2^(c-1)*(x/10^66666-(x/10^66666+x%10^33333)/2)^2/10^33333)*10^33333+sqrt((x/10^66666)*(x%10^33333));c&lt;=15;(x/10^66666+x%10^33333)^2/4/((x/10^33333)%10^33333)/1000;c==15</code></p>
<p>En este script escrito por Samuel Eraut: <var>b</var> = los 33333 dígitos menos significativos de <var>x</var>, <var>t</var> = los siguientes 33333 dígitos, <var>a</var> = los dígitos más significativos de <var>x</var>. Los nombres de variable <var>a</var>, <var>b</var> y <var>t</var> corresponden con lo que se muestra en el algoritmo de Gauss-Legendre en Wikipedia.</p>
<p>Ejemplo 5: Obtener 33331 dígitos de &pi; usando la fórmula de Bailey–Borwein–Plouffe (BBP) (script escrito por Samuel Eraut).</p>
<p><code>x=0;x=x+(2^(110742-c*4)/(8*(c-1)+1)-2^(110741-c*4)/(8*(c-1)+4)-2^(110740-c*4)/(8*(c-1)+5)-2^(110740-c*4)/(8*(c-1)+6));c&lt;=27674;x*10^33330/2^110736;c==27674</code></p>
</div>
<div class="noand">
<h2><button type="button">Código fuente</button></h2>
Expand Down
17 changes: 12 additions & 5 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "fromBlockly.h"
#include "isprime.h"
#ifndef DEBUG_CODE
#define DEBUG_CODE 16
#define DEBUG_CODE 13
#endif
#if (DEBUG_CODE == 9) || (DEBUG_CODE == 17)
extern bool teach;
Expand Down Expand Up @@ -261,13 +261,16 @@ int main(int argc, char* argv[])
char text[40000];
char* ptrText = text;
char* ptrCurveNbr = NULL;
if ((argc != 2) && (argc != 3))
bool doFactorization = true;
if ((argc < 2) || (argc > 4))
{
(void)printf("nbr_to_factor [flags]\n"
(void)printf("nbr_to_factor [flags] [dofact]\n"
"flags = 1: hexadecimal output, do not use SIQS\n"
"flags = 2: decimal output, use SIQS\n"
"flags = 3: hexadecimal output, use SIQS\n"
"flags = 4: decimal output, do not use SIQS\n");
"flags = 4: decimal output, do not use SIQS\n"
"dofact = 0: do not factor, just show expression result\n"
"dofact = 1: factor expression (default)\n");
return 0;
}
if (argc == 3)
Expand All @@ -281,9 +284,13 @@ int main(int argc, char* argv[])
ptrCurveNbr = "!"; // Use SIQS.
}
}
if ((argc == 4) && (argv[3][0] == '0'))
{
doFactorization = false;
}
copyStr(&ptrText, argv[1]);
copyStr(&ptrText, "\n");
ecmFrontText(text, true, ptrCurveNbr);
ecmFrontText(text, doFactorization, ptrCurveNbr);
(void)printf("%s\n", output);
#if 0
if (argc == 3)
Expand Down

0 comments on commit 6d26a59

Please sign in to comment.