eyeprolog 0.5.9 → 0.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/examples/fundamental-theorem-arithmetic.pl +3 -13
- package/examples/sieve.pl +33 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
[](https://www.npmjs.com/package/eyeprolog)
|
|
8
8
|
[](https://doi.org/10.5281/zenodo.21446308)
|
|
9
9
|
|
|
10
|
-
EyeProlog combines ISO Prolog and W3C RDF 1.2 to
|
|
11
|
-
inspectable proofs.
|
|
10
|
+
EyeProlog combines ISO Prolog and W3C RDF 1.2 to turn portable rules and linked data into answers and inspectable proofs.
|
|
12
11
|
|
|
13
12
|
**[Book — *The Art of EyeProlog*](https://eyereasoner.github.io/eyeprolog/the-art-of-eyeprolog)** ·
|
|
14
13
|
**[Why EyeProlog?](https://eyereasoner.github.io/eyeprolog/why-eyeprolog)** ·
|
|
@@ -37,19 +37,9 @@ divides(A, B) :-
|
|
|
37
37
|
(B > 0),
|
|
38
38
|
(0 is B mod A).
|
|
39
39
|
|
|
40
|
-
smallest_divisor_from
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
smallest_divisor_from(N, D, N) :-
|
|
44
|
-
(D2 is D * D),
|
|
45
|
-
(D2 > N).
|
|
46
|
-
|
|
47
|
-
smallest_divisor_from(N, D, S) :-
|
|
48
|
-
\+ divides(D, N),
|
|
49
|
-
(D2 is D * D),
|
|
50
|
-
(D2 =< N),
|
|
51
|
-
(D1 is D + 1),
|
|
52
|
-
smallest_divisor_from(N, D1, S).
|
|
40
|
+
% smallest_divisor_from/3 is supplied by eyeprolog-library.pl. Its
|
|
41
|
+
% implementation is plain Prolog and avoids repeating a long trial scan for
|
|
42
|
+
% values that are prime.
|
|
53
43
|
|
|
54
44
|
trial_prime(2).
|
|
55
45
|
trial_prime(3).
|
package/examples/sieve.pl
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
% Prime enumeration inspired by Eyelet input/sieve.pl.
|
|
2
2
|
% The 1000-limit answer matches Eyelet output-swipl/sieve.pl.
|
|
3
3
|
%
|
|
4
|
-
%
|
|
5
|
-
%
|
|
4
|
+
% A plain-Prolog 6k-1/6k+1 candidate wheel preserves the same generated prime
|
|
5
|
+
% list without requiring a host accelerator.
|
|
6
6
|
|
|
7
7
|
% Output declarations: host-supplied goals select the relations written to this example's golden output.
|
|
8
8
|
%% goal: primes(X0, X1)
|
|
@@ -12,9 +12,38 @@
|
|
|
12
12
|
want_primes(1000).
|
|
13
13
|
|
|
14
14
|
% Derivation rules: each rule below contributes one logical step toward the displayed results.
|
|
15
|
+
prime_under(Limit, 2) :-
|
|
16
|
+
(Limit >= 2).
|
|
17
|
+
|
|
18
|
+
prime_under(Limit, 3) :-
|
|
19
|
+
(Limit >= 3).
|
|
20
|
+
|
|
21
|
+
% Starting at 5, alternating steps of 2 and 4 generates exactly the 6k-1 and
|
|
22
|
+
% 6k+1 candidates, excluding every larger multiple of 2 or 3.
|
|
23
|
+
prime_candidate(Current, High, _, Current) :-
|
|
24
|
+
(Current =< High).
|
|
25
|
+
|
|
26
|
+
prime_candidate(Current, High, Step, Value) :-
|
|
27
|
+
(Current < High),
|
|
28
|
+
(Next is Current + Step),
|
|
29
|
+
(NextStep is 6 - Step),
|
|
30
|
+
!,
|
|
31
|
+
prime_candidate(Next, High, NextStep, Value).
|
|
32
|
+
|
|
33
|
+
prime_from(N, Divisor, _) :-
|
|
34
|
+
(Divisor * Divisor > N).
|
|
35
|
+
|
|
36
|
+
prime_from(N, Divisor, Step) :-
|
|
37
|
+
(Divisor * Divisor =< N),
|
|
38
|
+
(N mod Divisor =\= 0),
|
|
39
|
+
(Next is Divisor + Step),
|
|
40
|
+
(NextStep is 6 - Step),
|
|
41
|
+
!,
|
|
42
|
+
prime_from(N, Next, NextStep).
|
|
43
|
+
|
|
15
44
|
prime_under(Limit, P) :-
|
|
16
|
-
|
|
17
|
-
|
|
45
|
+
prime_candidate(5, Limit, 2, P),
|
|
46
|
+
prime_from(P, 5, 2).
|
|
18
47
|
|
|
19
48
|
primes(Limit, Ps) :-
|
|
20
49
|
want_primes(Limit),
|