3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-28 11:25:51 +00:00
Commit graph

44 commits

Author SHA1 Message Date
Facundo Domínguez
91cdc082c4
Optimize calls to Z3_eval_smtlib2_string (#6422)
* Allow reseting the stream of smt2::scanner

* Put the parser of parse_smt2_commands in the cmd_context

* Move parser streams to cmd_context

* Move parser fields from cmd_context to api::context

* Move forward declarations from cmd_context.h to api_context.h

* Change parse_smt2_commands_with_parser to use *& instead of **

* Add tests for Z3_eval_smtlib2_string

* Don't reuse the streams in Z3_eval_smtlib2_string

* Fix indentation

* Add back unnecessary deleted line

Co-authored-by: Nuno Lopes <nuno.lopes@tecnico.ulisboa.pt>
2022-10-28 13:57:22 -07:00
Nuno Lopes
1720addc4e remove a bunch of string copies in the API
thanks to C++20
2022-10-26 18:22:55 +01:00
Nikolaj Bjorner
107981f099 update proof formats for new core
- update proof format for quantifier instantiation to track original literals
- update proof replay tools with ability to extract proof object

The formats and features are subject to heavy revisions.

Example
```
(set-option :sat.euf true)
(set-option :sat.smt.proof eufproof.smt2)
(declare-fun f (Int) Int)
(declare-const x Int)
(assert (or (= (f (f (f x))) x) (= (f (f x)) x)))
(assert (not (= (f (f (f (f (f (f x)))))) x)))
(check-sat)
```

eufproof.smt2 is:
```
(declare-fun x () Int)
(declare-fun f (Int) Int)
(define-const $24 Int (f x))
(define-const $25 Int (f $24))
(define-const $26 Int (f $25))
(define-const $27 Bool (= $26 x))
(define-const $28 Bool (= $25 x))
(assume $27 $28)
(define-const $30 Int (f $26))
(define-const $31 Int (f $30))
(define-const $32 Int (f $31))
(define-const $33 Bool (= $32 x))
(assume (not $33))
(declare-fun rup () Proof)
(infer (not $33) rup)
(declare-fun euf (Bool Bool Proof Proof Proof Proof) Proof)
(declare-fun cc (Bool) Proof)
(define-const $42 Bool (= $32 $30))
(define-const $43 Proof (cc $42))
(define-const $40 Bool (= $31 $24))
(define-const $41 Proof (cc $40))
(define-const $38 Bool (= $30 $25))
(define-const $39 Proof (cc $38))
(define-const $36 Bool (= $24 $26))
(define-const $37 Proof (cc $36))
(define-const $34 Bool (not $33))
(define-const $44 Proof (euf $34 $28 $37 $39 $41 $43))
(infer (not $28) $33 $44)
(infer (not $28) rup)
(infer $27 rup)
(declare-fun euf (Bool Bool Proof Proof Proof) Proof)
(define-const $49 Bool (= $32 $26))
(define-const $50 Proof (cc $49))
(define-const $47 Bool (= $31 $25))
(define-const $48 Proof (cc $47))
(define-const $45 Bool (= $24 $30))
(define-const $46 Proof (cc $45))
(define-const $51 Proof (euf $34 $27 $46 $48 $50))
(infer $33 $51)
(infer rup)
```

Example of inspecting proof from Python:

```
from z3 import *

def parse(file):
    s = Solver()
    set_option("solver.proof.save", True)
    set_option("solver.proof.check", False)
    s.from_file(file)
    for step in s.proof().children():
        print(step)

parse("../eufproof.smt2")
```

Proof checking (self-validation) is on by default.
Proof saving is off by default.

You can use the proof logs and the proof terms to retrieve quantifier instantiations from the new core.

The self-checker contains a few built-in tuned checkers but falls back to self-checking inferred clauses using SMT.
2022-09-28 10:40:43 -07:00
Nuno Lopes
b9ddb11701 add static love 2022-09-04 11:57:43 +01:00
Nikolaj Bjorner
2f8b13368d add redirect for warnings
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2022-08-23 15:55:55 -07:00
Bruce Mitchener
5d0dea05aa
Remove empty leaf destructors. (#6211) 2022-07-30 10:07:03 +01:00
Nikolaj Bjorner
9dd529bb12 missing initialization of List for cmd interpreter 2022-07-11 08:17:38 -07:00
Nikolaj Bjorner
815518dc02 add facility for incremental parsing #6123
Adding new API object to maintain state between calls to parser.
The state is incremental: all declarations of sorts and functions are valid in the next parse. The parser produces an ast-vector of assertions that are parsed in the current calls.

The following is a unit test:

```
from z3 import *

pc = ParserContext()

A = DeclareSort('A')

pc.add_sort(A)
print(pc.from_string("(declare-const x A) (declare-const y A) (assert (= x y))"))
print(pc.from_string("(declare-const z A) (assert (= x z))"))

print(parse_smt2_string("(declare-const x Int) (declare-const y Int) (assert (= x y))"))

s = Solver()
s.from_string("(declare-sort A)")
s.from_string("(declare-const x A)")
s.from_string("(declare-const y A)")
s.from_string("(assert (= x y))")
print(s.assertions())
s.from_string("(declare-const z A)")
print(s.assertions())
s.from_string("(assert (= x z))")
print(s.assertions())
```

It produces results of the form

```
[x == y]
[x == z]
[x == y]
[x == y]
[x == y]
[x == y, x == z]
```
Thus, the set of assertions returned by a parse call is just the set of assertions added.
The solver maintains state between parser calls so that declarations made in a previous call are still available when declaring the constant 'z'.
The same holds for the parser_context_from_string function: function and sort declarations either added externally or declared using SMTLIB2 command line format as strings are valid for later calls.
2022-07-01 20:27:18 -07:00
Nuno Lopes
73a24ca0a9 remove '#include <iostream>' from headers and from unneeded places
It's harmful to have iostream everywhere as it injects functions in the compiled files
2022-06-17 14:10:19 +01:00
Nikolaj Bjorner
3c1aedf219 fixing #5473
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2021-11-30 17:08:28 -08:00
Nikolaj Bjorner
3abecc3428 add extra commands to API parser 2021-09-27 14:19:43 -07:00
Nikolaj Bjorner
d9af8ea9fb fix #5113 2021-04-07 12:20:12 -07:00
Nuno Lopes
8fda4f904d API: dont deref already free'd memory on error 2020-06-30 15:04:40 +01:00
Nikolaj Bjorner
4842c71019 fix #3537
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2020-04-05 00:38:14 -07:00
Nikolaj Bjorner
ce84e0f240 remove strategic solver header file
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2019-08-09 15:56:04 -07:00
Nikolaj Bjorner
f534f79a21 include all sorts from declarations, and include sorts from datatypes #2185
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2019-03-16 18:16:09 -07:00
Nikolaj Bjorner
c4829dfa22 fix #1577 again
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2018-10-06 09:01:01 -07:00
Nikolaj Bjorner
1eb8ccad59 overhaul of error messages. Add warning in dimacs conversion
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2018-07-04 16:04:37 -07:00
Nikolaj Bjorner
c513f3ca09 merge with master
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2018-03-25 14:57:01 -07:00
Nikolaj Bjorner
fc719a5ee8 fix diagnostic output #1553
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2018-03-24 10:37:05 -07:00
Nikolaj Bjorner
753f2c89ef initialize solvers to ensure that eval mode has a solver
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2018-03-23 18:54:23 -07:00
Nikolaj Bjorner
966a8f73d3 add eval feature #1553
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2018-03-23 16:26:20 -07:00
Bruce Mitchener
76eb7b9ede Use nullptr. 2018-02-12 14:05:55 +07:00
Nikolaj Bjorner
0bfea99cff fix issues found in parsing examples
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-12-01 14:43:52 -08:00
Nikolaj Bjorner
92b4b9e7a7 fix error messaging for parsers
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-11-28 11:14:00 -08:00
Nikolaj Bjorner
89971e2a98 remove smtlib1 dependencies
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-11-28 10:37:30 -08:00
Nikolaj Bjorner
6f8ff46ddb Merge branch 'opt' of https://github.com/nikolajbjorner/z3 into opt 2017-11-06 10:03:03 -08:00
Nikolaj Bjorner
d97f800390 update error code
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-11-06 10:02:59 -08:00
Nikolaj Bjorner
fd49a0c89c added facility to persist model transformations
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-11-02 00:05:52 -05:00
Nikolaj Bjorner
c093e6d4b9 harden a few API methods against longjumps in set_error. Memory leak exposed in #1297
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-10-11 09:53:02 -07:00
Nikolaj Bjorner
1a6f8c2fad working on parallel solver
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-10-10 16:35:05 -07:00
Nikolaj Bjorner
09ea370ea3 update C-example that fails to not use longjumps. Issue #1297
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-10-10 12:06:19 -07:00
Nikolaj Bjorner
7f693186a0 trying to address leak reported in #1297
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-10-10 07:10:04 -07:00
Nikolaj Bjorner
651587ce01 merge with master branch
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-09-19 09:39:22 -07:00
Dan Liew
a2d7b43554 Update header includes to be relative to src/ directory. 2017-08-17 18:26:53 +01:00
Nikolaj Bjorner
b19f94ae5b make include paths uniformly use path relative to src. #534
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-07-31 13:24:11 -07:00
Nikolaj Bjorner
0ac80fc042 have parser produce ast-vector instead of single ast
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2017-06-01 21:21:05 -07:00
Leonardo de Moura
2c9b14ada8 removed private API based on deprecated features
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-12-11 11:37:29 -08:00
Leonardo de Moura
589f096e6e working on new parameter framework
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-12-01 15:54:34 -08:00
Leonardo de Moura
d545f187f8 working on named assertions support
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-11-02 08:28:34 -07:00
Leonardo de Moura
cadd35bf7a checkpoint
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-11-01 21:44:35 -07:00
Leonardo de Moura
c2e95bb0c5 make front_end_params an optional argument in cmd_context
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-10-31 09:43:46 -07:00
Leonardo de Moura
95a25265f2 removed native low level parser
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-10-26 17:18:41 -07:00
Leonardo de Moura
dcf778a287 Reorganizing the code
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-10-21 14:16:35 -07:00
Renamed from lib/api_parsers.cpp (Browse further)