Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
34
Task/Jacobi-symbol/ALGOL-68/jacobi-symbol.alg
Normal file
34
Task/Jacobi-symbol/ALGOL-68/jacobi-symbol.alg
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
BEGIN # Jacobi symbol - translation of the Wren sample #
|
||||
|
||||
PROC jacobi = ( INT a in, n in )INT:
|
||||
IF n in <= 0 OR NOT ODD n in THEN
|
||||
print( ( "The 'n' parameter of jacobi must be an odd positive integer.", newline ) );
|
||||
stop
|
||||
ELSE
|
||||
INT a := a in MOD n in, n := n in;
|
||||
INT result := 1;
|
||||
WHILE a /= 0 DO
|
||||
WHILE NOT ODD a DO
|
||||
a OVERAB 2;
|
||||
INT nm8 = n MOD 8;
|
||||
IF nm8 = 3 OR nm8 = 5 THEN result := - result FI
|
||||
OD;
|
||||
INT t = a;
|
||||
a := n;
|
||||
n := t;
|
||||
IF a MOD 4 = 3 AND n MOD 4 = 3 THEN result := - result FI;
|
||||
a MODAB n
|
||||
OD;
|
||||
IF n = 1 THEN result ELSE 0 FI
|
||||
FI # jacobi # ;
|
||||
|
||||
print( ( "Table of jacobi(a, n):", newline ) );
|
||||
print( ( "n/a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", newline ) );
|
||||
print( ( "---------------------------------------------------------------", newline ) );
|
||||
FOR n BY 2 TO 29 DO
|
||||
print( ( whole( n, -3 ) ) );
|
||||
FOR a TO 15 DO print( ( whole( jacobi( a, n ), -4 ) ) ) OD;
|
||||
print( ( newline ) )
|
||||
OD
|
||||
|
||||
END
|
||||
33
Task/Jacobi-symbol/ALGOL-W/jacobi-symbol.alg
Normal file
33
Task/Jacobi-symbol/ALGOL-W/jacobi-symbol.alg
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
begin % Jacobi symbol %
|
||||
|
||||
integer procedure jacobi( integer value aIn, nIn ) ;
|
||||
if nIn <= 0 or not odd( nIn ) then begin
|
||||
write( "The 'n' parameter of jacobi must be an odd positive integer." );
|
||||
0
|
||||
end
|
||||
else begin
|
||||
integer a, n, js;
|
||||
a := aIn rem nIn; n := nIn; js := 1;
|
||||
while a not = 0 do begin
|
||||
while a rem 2 = 0 do begin
|
||||
integer nm8;
|
||||
a := a div 2;
|
||||
nm8 := n rem 8;
|
||||
if nm8 = 3 or nm8 = 5 then js := - js;
|
||||
end while_a_rem_2_eq_0 ;
|
||||
begin integer t; t := a; a := n; n := t end;
|
||||
if a rem 4 = 3 and n rem 4 = 3 then js := - js;
|
||||
a := a rem n
|
||||
end;
|
||||
if n = 1 then js else 0
|
||||
end jacobi ;
|
||||
|
||||
write( "Table of jacobi(a, n):" );;
|
||||
write( "n/a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" );
|
||||
write( "---------------------------------------------------------------" );
|
||||
for n := 1 step 2 until 29 do begin
|
||||
write( i_w := 3, s_w := 0, n );
|
||||
for a := 1 until 15 do writeon( i_w := 4, s_w := 0, jacobi( a, n ) );
|
||||
end
|
||||
|
||||
end.
|
||||
33
Task/Jacobi-symbol/Lua/jacobi-symbol.lua
Normal file
33
Task/Jacobi-symbol/Lua/jacobi-symbol.lua
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
do -- Jacobi symbol - translation of the Algol 68 sample
|
||||
|
||||
|
||||
local function jacobi( aIn, nIn )
|
||||
if nIn <= 0 or nIn % 2 == 0 then
|
||||
print( "The 'n' parameter of jacobi must be an odd positive integer." )
|
||||
return 0
|
||||
else
|
||||
local a, n, result = aIn % nIn, nIn, 1
|
||||
while a ~= 0 do
|
||||
while a % 2 == 0 do
|
||||
a = math.floor( a / 2 )
|
||||
local nm8 = n % 8
|
||||
if nm8 == 3 or nm8 == 5 then result = - result end
|
||||
end
|
||||
a, n = n, a;
|
||||
if a % 4 == 3 and n % 4 == 3 then result = - result end
|
||||
a = a % n
|
||||
end
|
||||
return n == 1 and result or 0
|
||||
end
|
||||
end
|
||||
|
||||
print( "Table of jacobi(a, n):" );
|
||||
print( "n/a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15" )
|
||||
print( "---------------------------------------------------------------" )
|
||||
for n = 1, 29, 2 do
|
||||
io.write( string.format( "%3d", n ) )
|
||||
for a = 1, 15 do io.write( string.format( "%4d", jacobi( a, n ) ) ) end
|
||||
io.write( "\n" )
|
||||
end
|
||||
|
||||
end
|
||||
69
Task/Jacobi-symbol/PL-M/jacobi-symbol.plm
Normal file
69
Task/Jacobi-symbol/PL-M/jacobi-symbol.plm
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
100H: /* JACOBI SYMBOL */
|
||||
|
||||
/* CP/M BDOS SYSTEM CALLS AND I/O ROUTINES */
|
||||
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
|
||||
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
|
||||
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
|
||||
PR$NL: PROCEDURE; CALL PR$STRING( .( 0DH, 0AH, '$' ) ); END;
|
||||
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
|
||||
DECLARE N ADDRESS;
|
||||
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
|
||||
V = N;
|
||||
W = LAST( N$STR );
|
||||
N$STR( W ) = '$';
|
||||
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
|
||||
DO WHILE( ( V := V / 10 ) > 0 );
|
||||
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
|
||||
END;
|
||||
CALL PR$STRING( .N$STR( W ) );
|
||||
END PR$NUMBER;
|
||||
|
||||
/* TASK */
|
||||
|
||||
JACOBI: PROCEDURE( A$IN, N$IN )BYTE;
|
||||
DECLARE ( A$IN, N$IN ) ADDRESS;
|
||||
IF N$IN MOD 2 <> 1 THEN DO;
|
||||
CALL PR$STRING( .'JACOBI PARAMETER NOT ODD$' );
|
||||
RETURN 0;
|
||||
END;
|
||||
ELSE DO;
|
||||
DECLARE ( A, N, NM8, T ) ADDRESS;
|
||||
DECLARE JS BYTE;
|
||||
A = A$IN MOD N$IN; N = N$IN; JS = 1;
|
||||
DO WHILE A <> 0;
|
||||
DO WHILE A MOD 2 = 0;
|
||||
A = A / 2;
|
||||
NM8 = N MOD 8;
|
||||
IF NM8 = 3 OR NM8 = 5 THEN JS = - JS;
|
||||
END;
|
||||
T = A; A = N; N = T;
|
||||
IF A MOD 4 = 3 AND N MOD 4 = 3 THEN JS = - JS;
|
||||
A = A MOD N;
|
||||
END;
|
||||
IF N = 1 THEN RETURN JS;
|
||||
ELSE RETURN 0;
|
||||
END;
|
||||
END JACOBI ;
|
||||
|
||||
DECLARE ( A, N )ADDRESS;
|
||||
DECLARE JS BYTE;
|
||||
|
||||
CALL PR$STRING( .'TABLE OF JACOBI(A, N):$' );CALL PR$NL;
|
||||
CALL PR$STRING( .'N/A 1 2 3 4 5 6 7$' );
|
||||
CALL PR$STRING( .' 8 9 10 11 12 13 14 15$' );CALL PR$NL;
|
||||
CALL PR$STRING( .'-------------------------------$' );
|
||||
CALL PR$STRING( .'--------------------------------$' );CALL PR$NL;
|
||||
DO N = 1 TO 29 BY 2;
|
||||
CALL PR$CHAR( ' ' );
|
||||
IF N < 10 THEN CALL PR$CHAR( ' ' );
|
||||
CALL PR$NUMBER( N );
|
||||
DO A = 1 TO 15;
|
||||
JS = JACOBI( A, N );
|
||||
IF JS = 0 THEN CALL PR$STRING( .' 0$' );
|
||||
ELSE IF JS = 1 THEN CALL PR$STRING( .' 1$' );
|
||||
ELSE CALL PR$STRING( .' -1$' );
|
||||
END;
|
||||
CALL PR$NL;
|
||||
END;
|
||||
|
||||
EOF
|
||||
|
|
@ -1,20 +1,22 @@
|
|||
func jacobi(n, k) {
|
||||
func jacobi(a, n) {
|
||||
|
||||
assert(k > 0, "#{k} must be positive")
|
||||
assert(k.is_odd, "#{k} must be odd")
|
||||
assert(n > 0, "#{n} must be positive")
|
||||
assert(n.is_odd, "#{n} must be odd")
|
||||
|
||||
var t = 1
|
||||
while (n %= k) {
|
||||
var v = n.valuation(2)
|
||||
t *= (-1)**v if (k%8 ~~ [3,5])
|
||||
n >>= v
|
||||
(n,k) = (k,n)
|
||||
t = -t if ([n%4, k%4] == [3,3])
|
||||
while (a %= n) {
|
||||
if (a.is_even) {
|
||||
var v = a.valuation(2)
|
||||
t *= (-1)**v if (n%8 ~~ [3,5])
|
||||
a >>= v
|
||||
}
|
||||
(a,n) = (n,a)
|
||||
t = -t if ([a%4, n%4] == [3,3])
|
||||
}
|
||||
|
||||
k==1 ? t : 0
|
||||
n==1 ? t : 0
|
||||
}
|
||||
|
||||
for n in (0..50), k in (0..50) {
|
||||
assert_eq(jacobi(n, 2*k + 1), kronecker(n, 2*k + 1))
|
||||
for a in (0..50), n in (0..50) {
|
||||
assert_eq(jacobi(a, 2*n + 1), kronecker(a, 2*n + 1))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import "/fmt" for Fmt
|
||||
import "./fmt" for Fmt
|
||||
|
||||
var jacobi = Fn.new { |a, n|
|
||||
if (!n.isInteger || n <= 0 || n%2 == 0) {
|
||||
|
|
@ -26,8 +26,8 @@ System.print("n/a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15")
|
|||
System.print("---------------------------------------------------------------")
|
||||
var n = 1
|
||||
while (n < 31) {
|
||||
System.write(Fmt.d(3, n))
|
||||
for (a in 1..15) System.write(Fmt.d(4, jacobi.call(a, n)))
|
||||
Fmt.write("$3d", n)
|
||||
for (a in 1..15) Fmt.write("$4d", jacobi.call(a, n))
|
||||
System.print()
|
||||
n = n + 2
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue