xmt_lib/lib.rs
1// cargo watch -x "doc --no-deps"
2
3#![doc = include_str!("../README.md")]
4
5
6//! # Rust API interface
7//!
8//! The programmable interface of xmt-lib is text based: commands are sent as strings,
9//! not as objects constructed in memory.
10//! This is similar to the approach used in interfaces for the web (HTML) and relational databases (SQL).
11//! An alternative is to construct commands in memory and submit the data structure via a call.
12//! We believe the string approach makes an acceptable compromise between performance and simplicity.
13//! Should we be wrong, we can easily make the memory-based API public.
14//!
15//! The Solver API is described [here](solver/struct.Solver.html).
16//!
17//! A solver instance has a connection to a sqlite database used for grounding assertions.
18//! This database can be pre-loaded with data describing the interpretation of symbols,
19//! as examplified in the [triangle crate](../triangle/index.html).
20//! The interpretation of a symbol can then be specified using the `(x-sql` construct, as described further below.
21//!
22//! The new commands introduced by xmt-lib are listed below.
23//! Note that, unlike SMT-Lib 2.6, but like the Z3 solver,
24//! xmt-lib accepts negative numbers in terms (e.g., `-1` is accepted for `(- 1)`).
25//!
26//!
27//! ## (set-option :backend ...)
28//!
29//! This command has the following variants:
30//!
31//! * `set-option :backend none` to obtain the translation of xmt-lib commands to SMT-Lib 2.6;
32//! * `set-option :backend Z3` for immediate execution of translated commands by a Z3 solver.
33//!
34//! By default, the backend is Z3.
35//! It can only be changed at the start of a session.
36//!
37//!
38//! ## (x-interpret-const ...)
39//!
40//! An `x-interpret-const` command specifies the interpretation of a constant.
41//! Such an intepretation can be given only once.
42//!
43//! Example: `(x-interpret-const c 1 )`.
44//! The value of constant `c` is `1`.
45//!
46//! For a proposition `p` (aka a boolean constant), the interpretation can be given as :
47//!
48//! * `(x-interpret-const p true )` if `p` is true;
49//! * `(x-interpret-const p false )` if `p` is false;
50//!
51//! Unlike an assertion about the value of a constant,
52//! the interpretation of a constant is used to simplify the grounding.
53//!
54//! Note that interpreted constants may take any value in a model obtained by `(get-model)`.
55//! So, in our example, `c` and `p` may have any value in a model.
56//!
57//!
58//! ## (x-interpret-pred ...)
59//!
60//! The `x-interpret-pred` command is used to specify the total interpretation of a boolean function symbol (aka a predicate),
61//! by listing all the tuples of arguments that make it true.
62//! Such an interpretation can be given only once.
63//!
64//! This list of tuples can be supplied using:
65//!
66//! * `(x-set`, e.g., `(x-interpret-pred Edge (x-set (a b) (b c) (c a)) )`.
67//! The only pairs of nodes that satisfy the `Edge` predicate are `(a b)`, `(b c)`, and `(c a)`.
68//!
69//! * `(x-sql "SELECT .. FROM ..")`.
70//! The SELECT is run using the sqlite connection of the solver.
71//! The SELECT must return `n` columns named `a_0, .. a_n`
72//! where `n` is the arity of the symbol being interpreted.
73//! These columns must be of type INTEGER for integers, REAL for reals, and TEXT otherwise,
74//! and contain nullary constructors.
75//!
76//! * `(x-range`, e.g., `(x-interpret-pred Row (x-range 1 8) )`.
77//! The values making Row true are 1, 2, 3, 4, 5, 6, 7, 8.
78//! The set is the (union of) interval with inclusive boundaries.
79//! This can only be used for unary predicates over Int.
80//!
81//! The list of tuples may not have duplicate tuples,
82//! and the values in the tuples must be of the appropriate type for the predicate.
83//!
84//! Note that the data integrity rules are not enforced for the `(x-sql` variant.
85//!
86//! Note that interpreted predicates may take any value in a model obtained by `(get-model)`.
87//! So, in our first example, `(Edge 1 1)` may have any value in a model.
88//!
89//!
90//! ## (x-interpret-fun ...)
91//!
92//! The `x-interpret-fun` command is used to specify the interpretation of a function symbol.
93//! If the domain of the function is finite, its interpretation is specified
94//! by mapping a value to some tuples of arguments in its domain,
95//! and by giving a default value for the remaining tuples in its domain.
96//! If the domain of the function is infinite, but its "domain of definition" is finite
97//! (i.e., the domain where its value is meaningful and relevant for the problem at hand),
98//! its interpretation is given by mapping a value to all tuples of arguments in its domain of definition.
99//! If the domain of definition of the function is infinite,
100//! one cannot specify its interpretation with this command:
101//! the SMT-Lib `(define-fun` command must be used instead.
102//!
103//! The grammar for this command is:
104//! ```text
105//! '(' 'x-interpret-fun' <symbol> <mappings> <default>? ')'
106//! ```
107//!
108//! The mappings can be supplied using:
109//!
110//! * ``` `(` `x-mapping` ['(' <tuple> <value> ')']* `)` ```
111//! where a tuple is a list of identifiers between parenthesis (e.g., `(a b)`),
112//! and a value is an identifier or `?` (for unknown value).
113//! The list of identifiers must match the arity of the function symbol.
114//! For example, `(x-mapping ((a b) 2) ((b c) ?) ((c a) 4) )`
115//! maps `(a b)` to 2, `(b c)` to unknown, and `(c a)` to 4
116//!
117//! * `(x-sql "SELECT .. FROM ..")`
118//! The SELECT is run using the sqlite connection of the solver.
119//! The SELECT must return `n+1` columns named `a_0, .. a_n, G`
120//! where `n` is the arity of the symbol being interpreted,
121//! `a_0, .. a_n` contain the tuples of arguments, and `G` the corresponding known values.
122//! These columns must be of type INTEGER for integers, REAL for reals, and TEXT otherwise.
123//! The values in the mappings must be nullary constructors (thus excluding "?")
124//! (note: this rule is not enforced by the xmtlib crate)
125//!
126//! The mappings may not have duplicate tuples,
127//! and the values in the mapping must be of the appropriate type.
128//!
129//! The default value may be `? `(for unknown).
130//! It may only be given for functions with finite domain
131//! when the set of tuples in the interpretation does not cover the domain;
132//! it may not be given otherwise.
133//!
134//! Note that pre-interpreted terms may take any value in a model obtained by `(get-model)`.
135//! (In our triangle example above,
136//! `(Length a b)` can have any interpretation in a model,
137//! but `(Length b c)` will have an interpretation that satisfies the assertions)
138//!
139//!
140//!
141//! ## (x-ground)
142//!
143//! Use `(x-ground)` to ground the pending assertions,
144//! i.e., to expand the finite quantifications in them,
145//! taking into account the known interpretations.
146//! Quantifications over infinite domains remain unchanged.
147//!
148//! The grounding of assertions is delayed until requested.
149//! It is thus possible to make assertions,
150//! then to give the interpretations of symbols,
151//! and then to ground the assertions using those interpretations.
152//!
153//! Note that `(check-sat)` grounds any pending assertions,
154//! making a prior call to `x-ground` unnecessary.
155//!
156//!
157//!
158//! # Command-line interface
159//!
160//! Usage: xmt-lib <FILE_PATH>
161//!
162//! Arguments:
163//! <FILE_PATH> Path to the script file containing XMT-Lib commands.
164//!
165//! Options:
166//! -h, --help Print help
167//! -V, --version Print version
168//!
169
170mod ast;
171pub mod error;
172mod grammar;
173pub mod solver;
174mod private;