Skip to content

Commit d148cfa

Browse files
committedOct 5, 2024
update to latest version
Changes: - use Scryer Prolog interactions - pull constraints into findall/3 so that no residual goals remain - logical --> logic
1 parent ee93f1b commit d148cfa

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed
 

‎presprover.pl

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22
Presprover -- Prove formulas of Presburger arithmetic
3-
Copyright (C) 2005, 2014, 2020 Markus Triska triska@metalevel.at
3+
Copyright (C) 2005-2023 Markus Triska (triska@metalevel.at)
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -64,49 +64,49 @@
6464
Some example queries and their results:
6565
6666
?- valid(x > 0).
67-
false.
67+
%@ false.
6868
6969
?- satisfiable(x > 0).
70-
true.
70+
%@ true.
7171
7272
?- valid(x >= 0).
73-
true.
73+
%@ true.
7474
7575
?- valid(exists(x, x > 0)).
76-
true.
76+
%@ true.
7777
7878
?- valid(forall(x, exists(y, 3*x + y > 2))).
79-
true.
79+
%@ true.
8080
8181
?- valid(2*y + 3*x = 30 /\ x = 0 ==> y = 15).
82-
true.
82+
%@ true.
8383
8484
?- valid(x = 3 \/ not(x=3)).
85-
true.
85+
%@ true.
8686
8787
?- valid(x = 5 ==> 2*x = 10).
88-
true.
88+
%@ true.
8989
9090
?- valid(y > 1 /\ x = 3 /\ x + y < 19 ==> x + 19 > y).
91-
true.
91+
%@ true.
9292
9393
You can use solution/1 to print solutions of satisfiable formulas:
9494
9595
?- solution(x > 100_000 /\ y = 20).
96-
x=114688.
97-
y=20.
98-
true .
96+
%@ x=114688.
97+
%@ y=20.
98+
%@ true
99+
%@ ; ...
99100
100-
For logical variables, solutions are reported as variable bindings:
101+
For logic variables, solutions are reported as variable bindings:
101102
102103
?- solution(X > 1_000_000_000 /\ Y > 10*X).
103-
X = 1536870912,
104-
Y = 16106127360 ;
105-
X = 1536870912,
106-
Y = 16106128384 ;
107-
X = 1536870912,
108-
Y = 16106127872 ;
109-
etc.
104+
%@ X = 1536870912, Y = 16106127360
105+
%@ ; X = 1536870912, Y = 16106128384
106+
%@ ; X = 1536870912, Y = 16106127872
107+
%@ ; X = 1536870912, Y = 16106127616
108+
%@ ; X = 1536870912, Y = 16106127488
109+
%@ ; ...
110110
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
111111

112112
:- module(presprover, [
@@ -209,7 +209,7 @@
209209

210210
saturate_eq([], _, AQ, AQ, D, D).
211211
saturate_eq([q(C)|QIterRest], Coeffs, AQ0, AQ, Delta0, Delta) :-
212-
eq_mod2(Coeffs, C, Tuples),
212+
findall(Vs, eq_mod2(Coeffs, C, Vs), Tuples),
213213
maplist(eq_tuple_newstate(Coeffs,C), Tuples, NewStates),
214214
maplist(state_tuple_delta(q(C)), NewStates, Tuples, NewDeltas),
215215
append(Delta0, NewDeltas, Delta1),
@@ -223,13 +223,14 @@
223223

224224
factor_mod2(C0, C) :- C #= abs(C0 mod 2).
225225

226-
eq_mod2(Coeffs0, C0, Tuples) :-
226+
eq_mod2(Coeffs0, C0, Vs) :-
227227
C #= abs(C0 mod 2),
228228
maplist(factor_mod2, Coeffs0, Coeffs),
229229
same_length(Coeffs, Vs),
230230
Vs ins 0..1,
231231
scalar_product(Coeffs, Vs, #=, S),
232-
findall(Vs, (S mod 2 #= C, label(Vs)), Tuples).
232+
S mod 2 #= C,
233+
label(Vs).
233234

234235

235236
eq_tuple_newstate(Coeffs, C, Tuple, q(D)) :-
@@ -249,8 +250,7 @@
249250
ineq_automaton(Coeffs, Sum, A) :-
250251
Q0 = q(Sum),
251252
same_length(Coeffs, Thetas),
252-
Thetas ins 0..1,
253-
findall(Thetas, label(Thetas), Tuples),
253+
findall(Thetas, (Thetas ins 0..1,label(Thetas)), Tuples),
254254
list_to_assoc([Q0-true], AQ0),
255255
saturate_ineq([Q0], Coeffs, Tuples, AQ0, AQ, [], Delta0),
256256
assoc_to_list(AQ, PQs),
@@ -523,8 +523,7 @@
523523
)
524524
; Delta = [delta(_,Seq,_)|_],
525525
same_length(Seq, Bits),
526-
Bits ins 0..1,
527-
findall(Bits, label(Bits), Binaries),
526+
findall(Bits, (Bits ins 0..1,label(Bits)), Binaries),
528527
aut_complete(Binaries, DFA, aut(Qs,QFs,Q0,CompleteDelta)),
529528
list_delete(QFs, Qs, CFinals0),
530529
exclude(pseudo_final_state(QFs,CompleteDelta), CFinals0, CFinals1),
@@ -857,7 +856,7 @@
857856
We establish the definitive order of variables occurring in the
858857
formula, and thus of the tracks in the automaton, by using
859858
list_to_set/2 on the list of all variables. This is more reliable
860-
than sort/2, since the relative (term-)order of logical variables
859+
than sort/2, since the relative (term-)order of logic variables
861860
may change (for example, due to garbage collection or stack
862861
shifting) during program execution in future Scryer versions.
863862
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

0 commit comments

Comments
 (0)
Please sign in to comment.