## arithmetic-derivative.a68

```
1  COMMENT
2
3  @section Synopsis
4
5  Lagarias arithmetic derivate.
6
7  Compute the Lagarias arithmetic derivative; a function defined for integers
8  based on prime factorization, an analogy of the product rule for the derivative
9  of a function in calculus. The function's relevance is in number-theoretic
10  conjectures like the twin prime conjecture, the prime triples conjecture,
11  and Goldbach's conjecture.
12
13  After the program published on Rosetta Code by Marcel van der Veer.
14
15  COMMENT
16
17  BEGIN PROC lagarias = (ZAHL n) ZAHL: # Lagarias arithmetic derivative #
18             IF n < 0
19             THEN -lagarias (-n)
20             ELIF n = 0 OR n = 1
21             THEN 0
22             ELIF PROC small pf = (ZAHL j, k) ZAHL: # Smallest prime factor #
23                       IF j MOD k = 0
24                       THEN k
25                       ELSE (k * k > j | j | small pf (j, k + 1))
26                       FI;
27                  ZAHL spf = small pf (n, 2);
28                  ZAHL q = n OVER spf;
29                  q = 1
30             THEN 1
31             ELSE q * lagarias (spf) + spf * lagarias (q)
32             FI;
33
34        FOR n FROM -99 TO 100
35        DO print (("D(", whole (n, 0), ") = ", whole (lagarias (n), 0), new line))
36        OD;
37        new line (standout);
38        FOR n TO 20
39        DO ZAHL m = LONG 10 ^ n;
40           print (("D(", whole (m, 0), ") / 7 = ", whole (lagarias (m) % 7, 0), new line))
41        OD
42  END

```