Library SMTSoundness

Require Export Classical.
Require Export SMT.

Interpreting terms and formulae


Definition interp := symbol -> Z.

Section Interpretation.

Variable I: interp.

Fixpoint term_interp(t: term): Z :=
  match t with
    t_lit z => z
  | t_symb s => I s
  | t_add t1 t2 => (term_interp t1 + term_interp t2)%Z
  end.

Fixpoint fsat(f: formula): Prop :=
  match f with
    f_eq t1 t2 => term_interp t1 = term_interp t2
  | f_lt t1 t2 => (term_interp t1 < term_interp t2)%Z
  | f_and f1 f2 => fsat f1 /\ fsat f2
  | f_not f => ~ fsat f
  end.

Soundness of the SMT solver


Import Solver.

Definition fssat facts := forall f, In f facts -> fsat f.

Fixpoint r0sat r0 :=
  match r0 with
    None => False
  | Some fs => fssat fs
  end.

Lemma assume_neq_sound facts t1 t2:
  fssat facts -> term_interp t1 <> term_interp t2 ->
  r0sat (assume_neq t1 t2 facts).

Lemma seq0_sound op1 op2 facts:
  r0sat (op1 facts) ->
  (forall facts', fssat facts' -> r0sat (op2 facts')) ->
  r0sat (seq0 op1 op2 facts).

Lemma assume_sound f:
  forall facts,
  (fsat f -> fssat facts -> r0sat (assume f facts)) /\
  (~ fsat f -> fssat facts -> r0sat (assume_false f facts)).

Lemma solver_sound f: solver f = valid -> fsat f.

Lemma follows_sound pc f:
  follows pc f = true -> fsat pc -> fsat f.

End Interpretation.

Free symbols: properties


Lemma fold_left_max_S ss: forall x, x <= fold_left (fun m s => max m (S s)) ss x.

Lemma In_lt_fold_left_max_S ss: forall x y, In x ss -> x < fold_left (fun m s => max m (S s)) ss y.

Lemma fresh_symbol_sound ss:
  ~ In (fresh_symbol ss) ss.

Lemma term_symbols_sound I I' t:
  (forall s, In s (term_symbols t) -> I s = I' s) ->
  term_interp I t = term_interp I' t.

Lemma formula_symbols_sound f:
  forall I I',
  (forall s, In s (formula_symbols f) -> I s = I' s) ->
  fsat I f -> fsat I' f.