Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
25
Task/Arithmetic-derivative/AWK/arithmetic-derivative.awk
Normal file
25
Task/Arithmetic-derivative/AWK/arithmetic-derivative.awk
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# syntax: GAWK -f ARITHMETIC_DERIVATIVE.AWK
|
||||
# converted from Action!
|
||||
BEGIN {
|
||||
for (n=-99; n<=100; n++) {
|
||||
l = 0
|
||||
f = 3
|
||||
z = (n < 0) ? -n : n
|
||||
while (z >= 2) {
|
||||
while (z % 2 == 0) {
|
||||
l += n / 2
|
||||
z /= 2
|
||||
}
|
||||
if (f <= z) {
|
||||
while (z % f == 0) {
|
||||
l += n / f
|
||||
z /= f
|
||||
}
|
||||
f += 2
|
||||
}
|
||||
}
|
||||
printf("%6d",l)
|
||||
if ((n+100) % 10 == 0) { printf("\n") }
|
||||
}
|
||||
exit(0)
|
||||
}
|
||||
55
Task/Arithmetic-derivative/Ada/arithmetic-derivative.adb
Normal file
55
Task/Arithmetic-derivative/Ada/arithmetic-derivative.adb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
|
||||
with Ada.Numerics.Big_Numbers.Big_Integers; use Ada.Numerics.Big_Numbers.Big_Integers;
|
||||
|
||||
procedure Arithmetic_Derivative is
|
||||
|
||||
function D (N : Big_Integer) return Big_Integer is
|
||||
Inc : Constant array (1 .. 8) of Big_Integer := (4, 2, 4, 2, 4, 6, 2, 6);
|
||||
I : Integer := 1;
|
||||
Num : Big_Integer := N;
|
||||
P : Big_Integer := 2;
|
||||
PCount : Big_Integer;
|
||||
Result : Big_Integer := 0;
|
||||
begin
|
||||
if N < 0 then return -D(-N); end if;
|
||||
if N = 0 or N = 1 then return 0; end if;
|
||||
|
||||
while P <= N / 2 loop
|
||||
if Num mod P = 0 then
|
||||
PCount := 0;
|
||||
while Num mod P = 0 loop
|
||||
Num := Num / P;
|
||||
PCount := PCount + 1;
|
||||
end loop;
|
||||
Result := Result + (PCount * N) / P;
|
||||
end if;
|
||||
if Num = 1 then exit; end if;
|
||||
if P >= 7 then
|
||||
P := P + Inc(I);
|
||||
I := (I mod 8) + 1;
|
||||
end if;
|
||||
if P = 3 or P = 5 then P := P + 2; end if;
|
||||
if P = 2 then P := P + 1; end if;
|
||||
end loop;
|
||||
|
||||
if Num > 1 then return 1; end if;
|
||||
|
||||
return result;
|
||||
end D;
|
||||
|
||||
P : Big_Integer;
|
||||
|
||||
begin
|
||||
for I in Integer range -99 .. 100 loop
|
||||
P := To_Big_Integer(I);
|
||||
Put(To_String(Arg => D(P), Width => 5));
|
||||
if I mod 10 = 0 then New_Line; end if;
|
||||
end loop;
|
||||
|
||||
for I in Integer range 1 .. 20 loop
|
||||
P := 10 ** I;
|
||||
Put("D(10^"); Put(Item => I, Width => 2); Put(") / 7 = ");
|
||||
Put(Big_Integer'Image(D(P) / 7)); New_Line;
|
||||
end loop;
|
||||
end Arithmetic_Derivative;
|
||||
33
Task/Arithmetic-derivative/Crystal/arithmetic-derivative.cr
Normal file
33
Task/Arithmetic-derivative/Crystal/arithmetic-derivative.cr
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
require "big"
|
||||
|
||||
struct Int
|
||||
def a_derivative
|
||||
if self < 0
|
||||
return -((-self).a_derivative)
|
||||
elsif self == 0 || self == 1
|
||||
return 0
|
||||
elsif self == 2
|
||||
return 1
|
||||
end
|
||||
d = self.class.new(2)
|
||||
result = self.class.new(1)
|
||||
while d * d <= self
|
||||
if self % d == 0
|
||||
q = self // d
|
||||
result = q * d.a_derivative + d * q.a_derivative
|
||||
break
|
||||
end
|
||||
d += 1
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
(-99..100).map(&.a_derivative).each_slice(10) do |row|
|
||||
puts row.map {|n| "%4d" % n }.join(" ")
|
||||
end
|
||||
|
||||
b10 = 10.to_big_i
|
||||
(1.to_big_i .. 20).each do |n|
|
||||
puts "D(10^%2d) / 7 = %d" % {n, (b10**n).a_derivative // 7}
|
||||
end
|
||||
107
Task/Arithmetic-derivative/Fortran/arithmetic-derivative.f
Normal file
107
Task/Arithmetic-derivative/Fortran/arithmetic-derivative.f
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
! Arithmetic derivative
|
||||
! tested with Intel ifx (IFX) 2025.2.1 20250806 on Kubuntu 25.10
|
||||
! GNU gfortran (Ubuntu 15.2.0-4ubuntu4) 15.2.0 on Kubuntu 25.10
|
||||
! VSI Fortran x86-64 V8.7-001 on OpenVMS V9.2-3
|
||||
|
||||
program AriDeri
|
||||
|
||||
implicit none
|
||||
|
||||
integer, parameter :: limit=100
|
||||
integer :: i, nInOneLine
|
||||
character (len=50) :: powD
|
||||
character (len=50) ::form
|
||||
! First part: D(n) for n=-99...100
|
||||
nInOneLine = 0
|
||||
Write (*,'(A)') ' D(k), k=-99...100:'
|
||||
Write (*,'(A,/)') ' =================='
|
||||
do i=-99,limit
|
||||
write (*,'(I4)', advance='no') arithmeticDerivative (i)
|
||||
nInOneLine = nInOneLine + 1
|
||||
if (nInOneLine .eq. 10) then
|
||||
write (*,*)
|
||||
nInOneLine = 0
|
||||
endif
|
||||
enddo
|
||||
write (*,*)
|
||||
|
||||
! Second part:
|
||||
! 1/7 * D(10^n) for n=1, 20
|
||||
!
|
||||
! We know that D(10) = 7, and we have the rule D(a*b) = a*D(b)+b*(D(a)
|
||||
! so D(10*10) = 10*D(10) + 10*D(10) = 140, D(100) = 140, and D(100)/7 = 20
|
||||
! D(10*100) = 10*D(100) + 100*D(10) = 10*140 + 100*7 = 2100, and D(1000)/7 = 300
|
||||
! This can be continued,by induction:
|
||||
! knowing 1/7 * D(10^k), we get for 1/7 * D(10^(k+1)) :
|
||||
! 1/7 * D(10^k+1) = 1/7 * (D(10^k)*10 + 10^k*D(10))
|
||||
! = 1/7 * (D(10^k)*10 + 10^k* D(10)) = 1/7 * (D(10^k)*10 + 10^k*7)
|
||||
! = 1/7*10*D(10^k) + 1/7*(10^k)*7)
|
||||
! = 10*1/7*D(10^k) + 10^k
|
||||
! The sequence is 1, 10+10=20, 200+100=300, 3000+1000=4000,40000+10000=50000, etc.
|
||||
! Hence we dont need to calculate with big integers, but just count 1..20 and append 0...19 zeroes.
|
||||
!
|
||||
write (*,'(A)') 'D(10^k) / 7, k=1...20'
|
||||
write (*,'(A,/)') '====================='
|
||||
do i=1,20
|
||||
! variable format to write to string powD the Numbers 1...20, followed by (0...19) * '0'
|
||||
if (i .gt. 1) then
|
||||
write (form, '("(I0,", i0, "(""0""))" )') i-1
|
||||
else
|
||||
form = '(I0)'
|
||||
endif
|
||||
powD = ' '
|
||||
write (powd, form) i
|
||||
write (*,'("D(10^",i2,") / 7 = ",A)') i, powd
|
||||
enddo
|
||||
contains
|
||||
|
||||
function arithmeticDerivative (argn) result (r)
|
||||
|
||||
integer, intent(in) :: argn
|
||||
integer :: r
|
||||
|
||||
integer :: n, sum, count, m
|
||||
integer :: p, sq
|
||||
|
||||
if (argn .ge. 0) then ! for n<0 we have D(n) = -D(-n)
|
||||
n = argn
|
||||
else
|
||||
n = -argn ! Calculate D(-n) and return -D(-n) later.
|
||||
endif
|
||||
|
||||
if (n .lt. 2) then ! Early return for smallest n
|
||||
r = 0
|
||||
return
|
||||
endif
|
||||
|
||||
sum=0
|
||||
count=0
|
||||
m=n
|
||||
|
||||
do while (mod(m,2) .eq. 0)
|
||||
m = m/2
|
||||
count = count + n
|
||||
enddo
|
||||
if (count .gt. 0) sum=sum+count/2
|
||||
|
||||
p = 3
|
||||
sq = 9
|
||||
|
||||
do while (sq .lt. m)
|
||||
count = 0
|
||||
do while (mod (m, p) .eq. 0)
|
||||
m = m / p
|
||||
count = count + n
|
||||
enddo
|
||||
if (count .gt. 0) sum = sum + count/p
|
||||
sq = sq + 2*(p+1)
|
||||
p = p + 2
|
||||
end do
|
||||
if (m .gt. 1) sum = sum + n/m
|
||||
|
||||
if (argn .lt. 0) sum = -sum
|
||||
|
||||
r = sum
|
||||
|
||||
end function arithmeticDerivative
|
||||
end program AriDeri
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
arith_deriv(x) := if member(x, [0, 1, -1]) then 0 else block(
|
||||
n: abs(x),
|
||||
facs: flatten(map(lambda([l], apply(makelist, l)), ifactors(n))),
|
||||
nfacs: length(facs),
|
||||
if nfacs=1 then signum(x) else block(
|
||||
d: first(facs)+second(facs),
|
||||
if nfacs>2 then block(
|
||||
c_prod: makelist(product(facs[i], i, 1, n), n, 1, nfacs),
|
||||
for i from 3 thru nfacs do d: facs[i]*d+c_prod[i-1]
|
||||
),
|
||||
signum(x)*d
|
||||
)
|
||||
)$
|
||||
|
||||
genmatrix(lambda([i, j], arith_deriv(10*(i-1)+j-100)), 20, 10);
|
||||
|
||||
for i from 1 thru 20 do print(sconcat("D(", 10^i, ")/7 = ", arith_deriv(10^i)/7));
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
MODULE ArithmeticDerivative; (* Translation of Algol W *)
|
||||
IMPORT Out;
|
||||
VAR n : INTEGER;
|
||||
|
||||
PROCEDURE lagarias( n : INTEGER ) : INTEGER; (* Lagarias arithmetic derivative *)
|
||||
VAR result, f, q : INTEGER;
|
||||
|
||||
PROCEDURE smallPf( j, k : INTEGER ) : INTEGER; (* Smallest prime factor *)
|
||||
VAR result : INTEGER;
|
||||
BEGIN
|
||||
IF j MOD k = 0 THEN result := k
|
||||
ELSIF k = 2 THEN result := smallPf( j, 3 )
|
||||
ELSE result := smallPf( j, k + 2 )
|
||||
END
|
||||
RETURN result
|
||||
END smallPf ;
|
||||
|
||||
BEGIN
|
||||
IF n < 0 THEN result := - lagarias( - n )
|
||||
ELSIF ( n = 0 ) OR ( n = 1 ) THEN result := 0
|
||||
ELSE
|
||||
f := smallPf( n, 2 ); q := n DIV f;
|
||||
IF q = 1 THEN result := 1 ELSE result := q * lagarias( f ) + f * lagarias( q ) END
|
||||
END
|
||||
RETURN result
|
||||
END lagarias ;
|
||||
|
||||
BEGIN
|
||||
FOR n := -99 TO 100 DO
|
||||
Out.String( " " );Out.Int( lagarias( n ), 6 );
|
||||
IF n MOD 10 = 0 THEN Out.Ln END
|
||||
END
|
||||
END ArithmeticDerivative.
|
||||
|
|
@ -1,13 +1,14 @@
|
|||
library(gmp) #for big number factorization
|
||||
options(scipen=20)
|
||||
|
||||
arith_deriv <- function(x){
|
||||
arith_deriv <- function(x) {
|
||||
if(x %in% c(0, 1, -1)) return(0)
|
||||
n <- abs(x)
|
||||
facs <- as.numeric(factorize(n))
|
||||
nfacs <- length(facs)
|
||||
if(nfacs==1) return(sign(x))
|
||||
if(nfacs == 1) return(sign(x))
|
||||
d <- sum(facs[1:2])
|
||||
if(nfacs>2){
|
||||
if(nfacs > 2) {
|
||||
c_prod <- cumprod(facs)
|
||||
for(i in 3:nfacs) d <- d*facs[i]+c_prod[i-1]
|
||||
}
|
||||
|
|
|
|||
48
Task/Arithmetic-derivative/Racket/arithmetic-derivative.rkt
Normal file
48
Task/Arithmetic-derivative/Racket/arithmetic-derivative.rkt
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#lang racket/base
|
||||
|
||||
(require
|
||||
math/number-theory
|
||||
racket/contract/base
|
||||
racket/match)
|
||||
|
||||
(provide
|
||||
(contract-out
|
||||
[δ (-> rational? rational?)]))
|
||||
|
||||
(define (∂ N)
|
||||
(let ([|N| (inexact->exact (abs N))])
|
||||
(for/sum ([power (in-list (factorize |N|))])
|
||||
(match-define (list prime expt) power)
|
||||
(/ expt prime))))
|
||||
|
||||
(define (δ m/n)
|
||||
(define m (numerator m/n))
|
||||
(define n (denominator m/n))
|
||||
(cond
|
||||
[(= 1 n) (* m (∂ m))]
|
||||
[else
|
||||
(/ (- (* n (δ m)) (* m (δ n)))
|
||||
(* n n))]))
|
||||
|
||||
(module+ test
|
||||
(require
|
||||
racket/format
|
||||
racket/string)
|
||||
|
||||
(define (align-number n width)
|
||||
(~a n #:min-width width #:align 'right))
|
||||
|
||||
(displayln "task: show arithmetic derivatives of the integers -99..100")
|
||||
(define cols (build-list 10 add1))
|
||||
(for ([row (in-inclusive-range -10 9)])
|
||||
(displayln
|
||||
(string-join
|
||||
(map (lambda (col) (align-number (δ (+ (* 10 row) col)) 5))
|
||||
cols)
|
||||
" │ ")))
|
||||
(newline)
|
||||
|
||||
(displayln "stretch task: show arithmetic derivatives of 10^m / 7 for m=1..20")
|
||||
(for ([n (in-inclusive-range 1 20)])
|
||||
(displayln
|
||||
(format "D(10^~a) / 7 = ~a" (align-number n 2) (/ (δ (expt 10 n)) 7)))))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
D′ ← |1 ⨬(
|
||||
⊸(=₁⧻)°/×
|
||||
⨬(+∩×⊃⋅⊙∘∘◡∩D′⊙/×°⊂|⋅1)
|
||||
| ⋅1
|
||||
)⊸<₂
|
||||
D ← ⨬D′⍜¯D′⊸<₀
|
||||
≡D-99⇡200
|
||||
÷7≡D˜ⁿ10+1⇡6
|
||||
18
Task/Arithmetic-derivative/V-(Vlang)/arithmetic-derivative.v
Normal file
18
Task/Arithmetic-derivative/V-(Vlang)/arithmetic-derivative.v
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
fn lagarias(nir int) int {
|
||||
if nir < 0 { return -lagarias(-nir) }
|
||||
if nir == 0 || nir == 1 { return 0 }
|
||||
mut fir := 2
|
||||
for fir <= nir && nir % fir != 0 {
|
||||
fir += 1
|
||||
}
|
||||
qir := nir / fir
|
||||
if qir == 1 { return 1 }
|
||||
return qir * lagarias(fir) + fir * lagarias(qir)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for nal in -99 .. 101 {
|
||||
print("${lagarias(nal)} ")
|
||||
}
|
||||
println("")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue