Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype SMT backend #273

Merged
merged 167 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
f5958cf
add: working on contract for collector
tnelson Jun 18, 2024
88127d4
add: template w/ Karim
tnelson Jun 18, 2024
9d1fcc2
add: Easy way to find Java Temp folder
tnelson Jun 19, 2024
ec18c92
change: send-to-kodkod -> send-to-solver
tnelson Jun 20, 2024
1f8de89
change: factor out pardinus backend
tnelson Jun 20, 2024
e38ad72
Merge branch 'dev' into feat_smt
tnelson Jun 20, 2024
5e6ed36
remove: experiment skeleton
tnelson Jun 20, 2024
d2ecaa0
Converted to format strings
k-mouline Jun 20, 2024
7fe890e
fix: ->
tnelson Jun 20, 2024
b82a887
first changes to parsing
k-mouline Jun 21, 2024
19da701
add: join builder, no preservation of loc
tnelson Jun 21, 2024
dfc9dbc
preserve syntax loc
tnelson Jun 21, 2024
03569ec
updated interpret calls
k-mouline Jun 24, 2024
8ec583b
examples added
k-mouline Jun 24, 2024
55e3c5a
pair with Karim, demo of match
tnelson Jun 24, 2024
c3aed57
identity parsing
k-mouline Jun 24, 2024
47ae4cf
NNF parser
k-mouline Jun 24, 2024
87ea87f
Draft of testing; needs to be validated
bisheshank Jun 25, 2024
68e42ad
Substitutor push
k-mouline Jun 25, 2024
f61ba63
updated testing; needs review
bisheshank Jun 25, 2024
17dd94c
updating substitutor
k-mouline Jun 26, 2024
7d83d9c
add: programming together in NNF/NNF testing, macros
tnelson Jun 26, 2024
5062063
quantifiers and decls fixed
k-mouline Jun 26, 2024
bf430e4
nnf testing updated; need to fix sig-rel contract vio
bisheshank Jun 26, 2024
d4e8a69
small sub tests and nnf conversion modified
k-mouline Jun 26, 2024
2c9de2e
verbosity added and sub tests
k-mouline Jun 26, 2024
23f820e
nnf-testing suite rewritten
bisheshank Jun 26, 2024
8d69be9
nff-test updated with comparision tests
bisheshank Jun 26, 2024
44d0280
refactor: one-sided integration prototype for cvc5
tnelson Jun 27, 2024
f1e5100
skolemization first implementation
k-mouline Jun 27, 2024
ff7e392
bounds propagate up
k-mouline Jun 27, 2024
7162ae1
add: additional refactoring around SMTlib backend
tnelson Jun 28, 2024
01dd402
minor: print out raw cvc5 response in sat case
tnelson Jun 28, 2024
2c8f5c6
working: basic parsing of SMTlib SAT response
tnelson Jun 28, 2024
eb4c77f
add: own-grandpa, sterling proof of concept
tnelson Jun 28, 2024
33f32d1
integer reconciliation
k-mouline Jun 28, 2024
a912f9a
first attempt at converting to smtlib
k-mouline Jun 28, 2024
649d3d6
add: working on integration. NNF and int-conversion in pipeline
tnelson Jun 29, 2024
abfa8ed
partial conversion, need to stop soon
tnelson Jun 29, 2024
e85656b
more adjustments to skolem
tnelson Jun 29, 2024
0c30972
add: more fixes, see initialed comments in skolem
tnelson Jun 29, 2024
c4c8fd1
add: final pipeline step
tnelson Jun 29, 2024
658ce7a
working through skolem, starting SMT conversion add
tnelson Jun 29, 2024
45b3297
rough mapping into cvc5, not done yet'
tnelson Jun 29, 2024
e26fd69
working on SMT conversion
tnelson Jun 29, 2024
59ebf96
fix: skolemize _inner_ formula as well. also fix var call order
tnelson Jun 29, 2024
c709c44
fix: quantifier IDs, more robust cmd line args
tnelson Jun 29, 2024
7ff052a
fix: use XSort in quantifier domains
tnelson Jun 29, 2024
1805e3c
intermediate checkpoint: multi-run is combining results
tnelson Jun 29, 2024
a4c7d5e
fix: singleton tuple processing. note failing test, skolem issue
tnelson Jun 29, 2024
83697e4
fix: skolem depth 0 only; cleanup
tnelson Jun 30, 2024
33c32fa
misc fixes, 3-ary relations
tnelson Jun 30, 2024
171e249
add test
tnelson Jul 1, 2024
9a1d174
add: print stderr from cvc5 in another location
tnelson Jul 1, 2024
52514ab
add: basic collector draft, working on smoke tests
tnelson Jul 2, 2024
3464314
update: collector
tnelson Jul 2, 2024
810c352
fix: ordering in collector, add tesT
tnelson Jul 2, 2024
ef54bb2
Small edits to skolemization
k-mouline Jul 2, 2024
d412ba1
atom test added
k-mouline Jul 3, 2024
ea59bec
several changes, mostly multiplicity
k-mouline Jul 3, 2024
6218d18
saving intermediate work
tnelson Jul 3, 2024
504ea94
adding tests
tnelson Jul 3, 2024
c46abe5
paren fix and beginning some work on ints
k-mouline Jul 3, 2024
0396f60
disable int literal checking for smtlibtor
tnelson Jul 3, 2024
0ab2f30
decl domains are expressions
tnelson Jul 3, 2024
5b8a834
add: fix errors with skolem, contract
tnelson Jul 3, 2024
9a2c532
working; will convert join to application on merge
tnelson Jul 3, 2024
e8a7c9f
convert join to application
tnelson Jul 3, 2024
5ae8d8c
add: allow Unknown message to Sterling; blank right now
tnelson Jul 3, 2024
b973852
defensive check
tnelson Jul 3, 2024
0fb298a
more int work
k-mouline Jul 3, 2024
a8dec28
merge
tnelson Jul 3, 2024
ba285b2
add: handle unknown in tests, etc. (cannot test much yet)
tnelson Jul 4, 2024
69c7123
to-skolem func args fixed
k-mouline Jul 5, 2024
0cda303
fun spacer maintained in substitutor
k-mouline Jul 5, 2024
df80e05
fix: error message string
tnelson Jul 5, 2024
9358764
add: pair programming
tnelson Jul 5, 2024
a7534bb
add: comment only, thinking re: int
tnelson Jul 5, 2024
06d4100
add: Goldbach for unsat
tnelson Jul 5, 2024
b614800
Vars and decls sorted out
k-mouline Jul 5, 2024
64d1b15
resolve conflict
tnelson Jul 8, 2024
a6574ce
fix: missing annotation #f
tnelson Jul 8, 2024
972ba22
add: annotation to qvar for smtlib integer conversion'
tnelson Jul 8, 2024
ae0d390
add: draft annotation use
tnelson Jul 8, 2024
0fb841e
add: define sign SMT function, question re ints
tnelson Jul 8, 2024
4e114a8
add: comment, question about ints
tnelson Jul 8, 2024
26a74a2
add: untangle expr/const case
tnelson Jul 8, 2024
6ae6ae9
add: relational update unsupported
tnelson Jul 8, 2024
a4bfc03
add: draft for translating none
tnelson Jul 8, 2024
b874a48
add: notes on int
tnelson Jul 8, 2024
dfd6128
oops
tnelson Jul 8, 2024
7c48a42
add: proof of concept, pair programming with Karim
tnelson Jul 8, 2024
b54323c
add: stop policy to collector
tnelson Jul 8, 2024
87342b7
fix: hacky fix for substitutor fun-spacer; needs expanding
tnelson Jul 9, 2024
32a92e0
quantifier grounding added
k-mouline Jul 9, 2024
efc57cf
fake run added
k-mouline Jul 9, 2024
a07b349
fix: minor to collector, add grandpa
tnelson Jul 9, 2024
80a1c1e
Comparison pull request (#265)
k-mouline Aug 1, 2024
e0686e8
patch
tnelson Aug 1, 2024
37d99b6
manual merge from dev
tnelson Aug 1, 2024
cc08cd9
minor: comment change to avoid confusion
tnelson Aug 1, 2024
35e7e4b
minor: comment fix
tnelson Aug 1, 2024
0c3e9e5
fix: get-annotation for nodes
tnelson Aug 1, 2024
2e22980
Fixing issue with to-smt visitor; refactor lang-specific error code (…
tnelson Aug 5, 2024
4cfef1a
fix: quantifier case in tor conversion
tnelson Aug 5, 2024
7717a47
fix: blocking in error case from cvc5
tnelson Aug 5, 2024
d4509d5
Comprehension and integer handling improved
k-mouline Aug 5, 2024
f9e4855
fix: parsing smt response, allow 'some Node'
tnelson Aug 5, 2024
cbc2b61
rename univInt, no longer pass IntAtom-to-Int
tnelson Aug 5, 2024
9e669dc
Cardinality supported, a few fixes needed
k-mouline Aug 6, 2024
9d4ed97
match against nested ites
tnelson Aug 7, 2024
5a1adf3
fix: issue with chained ite
tnelson Aug 7, 2024
dfc5daa
fix: negative numbers in IntAtom-to-Int
tnelson Aug 7, 2024
ea152f2
fix more
tnelson Aug 7, 2024
83e7bbc
fix: update sterling for larger numbers
tnelson Aug 7, 2024
af90532
Added more comp/card tests, added to expression-type struct
k-mouline Aug 7, 2024
462edb1
fix: remove leftover prints
tnelson Aug 8, 2024
7923a0d
fix: arity of function call
tnelson Aug 8, 2024
b05b7d5
Tests for Tim
k-mouline Aug 8, 2024
4aae72f
fix to use of 'second' in last-checker, clarifying comments
tnelson Aug 8, 2024
f3c86d4
Multiplicities fixed and tests added
k-mouline Aug 8, 2024
fa5b2e3
More tests
k-mouline Aug 12, 2024
48769bc
Relational override, reflexive tc typing, lone sig, and tests
k-mouline Aug 14, 2024
212463a
add: don't pass translation-helpers to sterling
tnelson Aug 14, 2024
17cde9e
Fixed cardinality of size 0 set typing
k-mouline Aug 14, 2024
dce6b19
Cardinality error fixed
k-mouline Aug 14, 2024
24a8905
add: finite int set, commented test example
tnelson Aug 15, 2024
1a23e3e
add: additional comment
tnelson Aug 15, 2024
b11ffa8
Plenty more tests added
k-mouline Aug 16, 2024
e9cbfeb
Tests fixed
k-mouline Aug 19, 2024
3312ac6
update pardinus: return parse error text
tnelson Aug 20, 2024
2768b8b
fix for non-smt, which gives no Int sig in instances
tnelson Aug 20, 2024
d91d825
Feat smt s exp (#271)
tnelson Aug 20, 2024
4bcfe5b
Fix prime check (#272)
tnelson Aug 20, 2024
f167639
Extra files removed
k-mouline Aug 20, 2024
8b62e4a
fix: skolemization tests robust to suffix
tnelson Aug 20, 2024
ff2ca40
S-exp descent and substitution added
k-mouline Aug 21, 2024
876db0e
Small errors fixed
k-mouline Aug 21, 2024
13c725b
refactor: SMT ToR tests into CI folder
tnelson Aug 21, 2024
3d8df26
Two out of three tests fixed
k-mouline Aug 21, 2024
2fefb34
remove outdated test
tnelson Aug 21, 2024
cc34513
Temp file added for verbose SMT runs
k-mouline Aug 21, 2024
f29b42c
cleanup verbosity, test cvc5 in CI
tnelson Aug 22, 2024
8efdc1e
experiment: actions
tnelson Aug 22, 2024
c67df5e
refine CI, update racket version and print cvc5 version
tnelson Aug 22, 2024
6b961d2
Wrap negative numbers for earlier cvc5 versions
tnelson Aug 22, 2024
7b068ed
fix: wrap -1 in sign built-in
tnelson Aug 22, 2024
e101a6d
minor: cleanup
tnelson Aug 22, 2024
a9f2c6d
add: more comprehension tests
tnelson Aug 22, 2024
54fe251
fix: uniqueness of ints, regression tests
tnelson Aug 22, 2024
da9777c
add: understanding ic3 example
tnelson Aug 23, 2024
66f377d
fix: remainder lambda
tnelson Aug 23, 2024
d01c5a9
minor fixes, mod
tnelson Sep 2, 2024
fe8d3e0
add: avoid asserting true
tnelson Sep 29, 2024
0c23720
add: include options in SMT-lib, not command line, where applicable
tnelson Sep 29, 2024
60a292f
add: simplify 'one' constraint
tnelson Oct 1, 2024
61d7392
adjust CI
tnelson Oct 15, 2024
050b654
update: CI
tnelson Oct 15, 2024
740b65b
smt tests verbosity set to 0
k-mouline Oct 17, 2024
85ca793
add: improve debugging line in reader
tnelson Oct 23, 2024
8fd9b3d
add: exclude examples from domains from compile
tnelson Nov 12, 2024
9ef1c70
Docker container for CI (#280)
k-mouline Nov 19, 2024
ccc9da5
add: null for PR in CI script
tnelson Nov 19, 2024
d654466
Merge branch 'dev' into feat_smt
tnelson Nov 19, 2024
d1dbee2
update: continue reconciling dev with feature branch
tnelson Nov 19, 2024
6d650ef
fix: is_theorem_disabled test, ++ case in smtlibtor conversion
tnelson Nov 19, 2024
82ca78a
cleanup: SMT / solver specifics
tnelson Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: uniqueness of ints, regression tests
  • Loading branch information
tnelson committed Aug 22, 2024
commit 54fe251a91ae709130a1ca8cd14624c2d8dce170
9 changes: 6 additions & 3 deletions forge/solver-specific/cvc5-tor.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@
; 7/25: Commented out quantifier grounding for now.
; (define step3 (map (lambda (f) (quant-grounding:interpret-formula new-fake-run f relations all-atoms '() '() step2-bounds)) step2))

(define step4 (map (lambda (f) (smt-tor:convert-formula new-fake-run f relations all-atoms '() '() total-bounds)) step1))
; Because this was written with mutation, we need to manually reset its top-level constraint library
(smt-tor:clear-new-top-level-strings)
(define step4 (map (lambda (f) (smt-tor:convert-constraint new-fake-run f relations all-atoms '() '() total-bounds)) step1))
(when (@> (get-verbosity) VERBOSITY_LOW)
(printf "~nStep 3 (post SMT-LIB conversion):~n")
(for ([constraint step4])
Expand All @@ -243,7 +245,7 @@
; (printf " ~a/lower: ~a~n" (bound-relation bound) (bound-lower bound))
; (printf " ~a/upper: ~a~n" (bound-relation bound) (bound-upper bound)))
)

; Now, convert bounds into SMT-LIB (theory of relations) and assert all formulas

; Preamble: the (reset) makes (set-logic ...) etc. not give an error on 2nd run
Expand Down Expand Up @@ -277,7 +279,8 @@
; No core support yet, see pardinus for possible approaches
(define (get-next-cvc5-tor-model is-running? run-name all-rels all-atoms core-map stdin stdout stderr [mode ""]
#:run-command run-command)
(printf "Getting next model from CVC5...~n")
(when (@> (get-verbosity) VERBOSITY_LOW)
(printf "Getting next model from CVC5...~n"))

; If the solver isn't running at all, error:
(unless (is-running?)
Expand Down
26 changes: 26 additions & 0 deletions forge/tests/smt/smtlibtor/comprehension_testing.frg
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,30 @@ test expect {
two_equal_sameage_quant: {
some p1, p2: Person | p1=p2 and p1+p2 = {q : Person | some r: Person-q | r.age = q.age}
} is unsat

-- exists-forall outer quantification testing
-- There is someone who is a different age from everyone else,
-- phrased elaborately via comprehensions. `p1` is not used in the comprehension.

ea_mixed_outer_sat: {
some p1: Person | all p2: Person-p1 | {
p1 not in {q : Person | p2.age = q.age}
}
} is sat
ea_mixed_outer_unsat: {
#Person > 1
some p1: Person | all p2: Person-p1 | {
p1 not in {q : Person | p2.age = q.age}
p1 in {r : Person | p2.age = r.age}
}
} is unsat

-- Int quantification
some_int_same: {
some i: Int | i = {i2: Int | some p: Person | p.age = i2}
} is sat
some_int_same_diff: {
#Int > 1
all i: Int | i = {i2: Int | some p: Person | p.age = i2}
} is unsat
}
47 changes: 47 additions & 0 deletions forge/tests/smt/smtlibtor/int_relational.frg
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,51 @@ test expect {
sing_1 : using_sing_1 is sat
sing_2 : using_sing_2 is sat
sing_sum : sing_sum_stack is sat
}

/** Regression tests for uniqueness of integer values */
test expect {
regression_int_unique_eq: {
some x: Int | {
x = 1
x = 2
}
} is unsat

regression_int_unique_in: {
some y: Int | {
y in 3
y in 4
}
} is unsat

regression_int_unique_ni: {
some z: Int | {
5 in z
6 in z
}
} is unsat

regression_int_unique_in_union: {
some y: Int | {
y in 13+14+15
y in 16+17+18
}
} is unsat

int_unique_with_arithmetic: {
some a: Int | {
a in add[100,200]
a in add[300,400]
}
} is unsat

int_unique_dependent: {
some a: Int | some disj p1, p2: Person {
p1.age != p2.age
a in add[p1.age, 1]
a in add[p2.age, 1]
}
} is unsat

}
58 changes: 41 additions & 17 deletions forge/utils/to-smtlib-tor.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
(prefix-in @ (only-in racket/contract -> ->*))
(prefix-in @ (only-in racket/base >= > - + < *)))

(provide convert-formula get-new-top-level-strings)
(provide convert-constraint get-new-top-level-strings clear-new-top-level-strings)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Boolean formulas
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define new-top-level-strings '())
(define new-top-level-strings (box '()))

(define (get-new-top-level-strings)
new-top-level-strings
)
(unbox new-top-level-strings))
(define (clear-new-top-level-strings)
(set-box! new-top-level-strings '()))

; Top-level conversion function for other modules to call.
(define (convert-constraint formula relations atom-names quantvars quantvar-types bounds [int-ctxt #f])
(convert-formula formula relations atom-names quantvars quantvar-types bounds int-ctxt))

; Translate a formula AST node
(define/contract (convert-formula run-or-state formula relations atom-names quantvars quantvar-types bounds [int-ctxt #f])
Expand Down Expand Up @@ -248,9 +253,12 @@
)

(define (form-comprehension run-or-state expr relations atom-names quantvars quantvar-types decls bounds processed-form)

; step 1: collect each of the variables in the formula
(define collector-lambda (lambda (n ctxt) (if (node/expr/quantifier-var? n) n #f)))
(define comprehension-quantvars (remove-duplicates (collect expr collector-lambda #:order 'pre-order)))
;(define collector-lambda (lambda (n ctxt) (if (node/expr/quantifier-var? n) n #f)))
;(define comprehension-quantvars (remove-duplicates (collect expr collector-lambda #:order 'pre-order)))
; ^ Unused now. Strategy is based only on outer context and decls of the comprehension itself.

; step 2: split up the decls
(define decl-vars (map car decls))
(define decl-types (map cdr decls))
Expand Down Expand Up @@ -280,7 +288,7 @@
(set.subset ,subset-string ,get-set)))))
; first subset is ensuring quantvars are in the decl set
; second subset is ensuring quantvars are in the new set
(set! new-top-level-strings (append new-top-level-strings (list declaration-str constraint-str) ))
(set-box! new-top-level-strings (append (get-new-top-level-strings) (list declaration-str constraint-str) ))
get-set
)

Expand All @@ -289,24 +297,40 @@
; This allows for us to not worry about type mismatches between Int and IntAtom, because
; any Int wrapped in a singleton (aka becoming a (Relation Int)) will now produce a set
; that is really just a (Relation IntAtom), and so whatever it is being compared to will
; certainly also be a (Relation IntAtom).
; certainly also be a (Relation IntAtom).

; Concrete example: (+ 5 5) yields an Int
; If we must convert that to an IntAtom, we can't use IntAtom-to-Int, because that's the
; wrong direction. Instead, we'll do something similar to what we do for comprehensions:
; create a distinct SMT function that accepts the variables free in the child expression
; and evaluates to a (Relation IntAtom). E.g.,
; (+ p.age 5) needs to vary depending on the environment value for variable `p`.

(define argument-vars quantvars)
(define argument-types (map (lambda (var) (cdr (assoc var quantvar-types))) quantvars))

(define set-name (string->symbol (format "_~a_comp" (gensym))))
(define declaration-str `(declare-fun ,set-name (,@(map (lambda (x) (atom-or-int x)) argument-types)) (Relation IntAtom)))
(define get-set (if (equal? (length argument-vars) 0)
(string->symbol (format "~a" set-name))
`(,set-name ,@(map (lambda (var) (string->symbol (format "~a" var))) argument-vars))))
(define constraint-pairs (map cons argument-vars argument-types))
(define const-name (string->symbol (format "_~a_atom" (gensym))))
(define new-decl `(declare-const ,const-name IntAtom))
(define new-constraint `(= (IntAtom-to-Int ,const-name) ,(car processed-form)))
;(define const-name (string->symbol (format "_~a_atom" (gensym))))
;(define new-decl `(declare-const ,const-name IntAtom))
;(define new-constraint `(= (IntAtom-to-Int ,const-name) ,(car processed-form)))

(define constraint-str (if (equal? (length constraint-pairs) 0)
`(assert (and ,new-constraint (set.subset (set.singleton (tuple ,const-name)) ,get-set)))
`(assert (exists (,@(map (lambda (x) (string->symbol (format "(~a ~a)" (car x) (atom-or-int (cdr x))))) constraint-pairs))
(and ,new-constraint (set.subset (set.singleton (tuple ,const-name)) ,get-set))))))
(set! new-top-level-strings (append (list new-decl declaration-str) new-top-level-strings))
(set! new-top-level-strings (append new-top-level-strings (list constraint-str)))
`(assert (and ;,new-constraint
;(set.subset (set.singleton (tuple ,const-name)) ,get-set)))
(= ,(car processed-form) (IntAtom-to-Int (reconcile-int_atom ,get-set)))))
`(assert (forall (,@(map (lambda (x) (string->symbol (format "(~a ~a)" (car x) (atom-or-int (cdr x))))) constraint-pairs))
(and ;,new-constraint
;(set.subset (set.singleton (tuple ,const-name)) ,get-set))))))
(= ,(car processed-form) (IntAtom-to-Int (reconcile-int_atom ,get-set)))
(set.is_singleton ,get-set))))))

(set-box! new-top-level-strings (append (list #;new-decl declaration-str) (get-new-top-level-strings)))
(set-box! new-top-level-strings (append (get-new-top-level-strings) (list constraint-str)))
get-set
)

Expand Down Expand Up @@ -522,7 +546,7 @@
(define const-name (string->symbol (format "_~a_atom" (gensym))))
(define new-decl `(declare-const ,const-name IntAtom))
(define new-constraint `(assert (= (IntAtom-to-Int ,const-name) ,value)))
(set! new-top-level-strings (append (list new-decl new-constraint) new-top-level-strings))
(set-box! new-top-level-strings (append (list new-decl new-constraint) (get-new-top-level-strings)))
(string->symbol (format "~a" const-name))])]
[(node/int/op info args)
(convert-int-op run-or-state expr relations atom-names quantvars quantvar-types args bounds)]
Expand Down
Loading