96d1407
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96d1407
;
96d1407
; SMT syntax and semantics (not theory-specific)
96d1407
;
96d1407
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96d1407
96d1407
(declare formula type)
96d1407
(declare th_holds (! f formula type))
96d1407
96d1407
; constants
96d1407
(declare true formula)
96d1407
(declare false formula)
96d1407
96d1407
; logical connectives
96d1407
(declare not (! f formula formula))
96d1407
(declare and (! f1 formula (! f2 formula formula)))
96d1407
(declare or (! f1 formula (! f2 formula formula)))
96d1407
(declare impl (! f1 formula (! f2 formula formula)))
96d1407
(declare iff (! f1 formula (! f2 formula formula)))
96d1407
(declare xor (! f1 formula (! f2 formula formula)))
96d1407
(declare ifte (! b formula (! f1 formula (! f2 formula formula))))
96d1407
96d1407
; terms
96d1407
(declare sort type)		; sort in the theory
96d1407
(declare arrow (! s1 sort (! s2 sort sort)))	; function constructor
96d1407
96d1407
(declare term (! t sort type))	; declared terms in formula
96d1407
96d1407
(declare apply (! s1 sort
96d1407
               (! s2 sort
96d1407
               (! t1 (term (arrow s1 s2))
96d1407
               (! t2 (term s1)
96d1407
                (term s2))))))
96d1407
                
96d1407
(declare ite (! s sort
96d1407
             (! f formula
96d1407
             (! t1 (term s)
96d1407
             (! t2 (term s)
96d1407
               (term s))))))
96d1407
96d1407
; let/flet
96d1407
(declare let (! s sort
96d1407
             (! t (term s)
96d1407
             (! f (! v (term s) formula)
96d1407
               formula))))
96d1407
(declare flet (! f1 formula
96d1407
              (! f2 (! v formula formula)
96d1407
                formula)))
96d1407
96d1407
; predicates
96d1407
(declare = (! s sort
96d1407
           (! x (term s)
96d1407
           (! y (term s)
96d1407
             formula))))
96d1407
96d1407
(declare distinct (! s sort
96d1407
                  (! x (term s)
96d1407
                  (! y (term s)
96d1407
                    formula))))
96d1407
96d1407
; To avoid duplicating some of the rules (e.g., cong), we will view
96d1407
; applications of predicates as terms of sort "Bool".
96d1407
; Such terms can be injected as atomic formulas using "p_app".
96d1407
96d1407
(declare Bool sort)							; the special sort for predicates
96d1407
(declare p_app (! x (term Bool) formula))	; propositional application of term
96d1407
96d1407
96d1407
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
96d1407
; Examples
96d1407
96d1407
; an example of "(p1 or p2(0)) and t1=t2(1)"
96d1407
;(! p1 (term Bool)
96d1407
;(! p2 (term (arrow Int Bool))
96d1407
;(! t1 (term Int)
96d1407
;(! t2 (term (arrow Int Int))
96d1407
;(! F (th_holds (and (or (p_app p1) (p_app (apply _ _ p2 0)))
96d1407
;                    (= _ t1 (apply _ _ t2 1))))
96d1407
;  ...
96d1407
96d1407
; another example of "p3(a,b)"
96d1407
;(! a (term Int)
96d1407
;(! b (term Int)
96d1407
;(! p3 (term (arrow Int (arrow Int Bool)))	; arrow is right assoc.
96d1407
;(! F (th_holds (p_app (apply _ _ (apply _ _ p3 a) b))) ; apply is left assoc.
96d1407
;  ...
96d1407
96d1407
; natural deduction rules here
96d1407
96d1407
(declare LEM 
96d1407
  (! f formula
96d1407
    (th_holds (or (not f) f))))
96d1407
96d1407
; bottom elim
96d1407
(declare bottom_elim  
96d1407
  (! f formula
96d1407
  (! u bottom
96d1407
    (th_holds f))))
96d1407
96d1407
96d1407
;; not not
96d1407
96d1407
(declare not_not_intro
96d1407
  (! f formula
96d1407
  (! u (th_holds f)
96d1407
    (th_holds (not (not f))))))
96d1407
    
96d1407
(declare not_not_elim
96d1407
  (! f formula
96d1407
  (! u (th_holds (not (not f)))
96d1407
    (th_holds f))))
96d1407
96d1407
;; or elimination
96d1407
96d1407
(declare or_elim_1
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u1 (th_holds (not f1))
96d1407
  (! u2 (th_holds (or f1 f2))
96d1407
    (th_holds f2))))))
96d1407
    
96d1407
(declare or_elim_2
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u1 (th_holds (not f2))
96d1407
  (! u2 (th_holds (or f1 f2))
96d1407
    (th_holds f1))))))
96d1407
96d1407
;; and elimination
96d1407
96d1407
(declare and_intro
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u1 (th_holds f1)
96d1407
  (! u2 (th_holds f2)
96d1407
    (th_holds (and f1 f2)))))))
96d1407
96d1407
(declare and_elim_1
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u (th_holds (and f1 f2))
96d1407
    (th_holds f1)))))
96d1407
    
96d1407
(declare and_elim_2
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u (th_holds (and f1 f2))
96d1407
    (th_holds f2)))))
96d1407
    
96d1407
;; not impl elimination
96d1407
96d1407
(declare not_impl_elim_1
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u (th_holds (not (impl f1 f2)))
96d1407
    (th_holds f1)))))
96d1407
    
96d1407
(declare not_impl_elim_2
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u (th_holds (not (impl f1 f2)))
96d1407
    (th_holds (not f2))))))
96d1407
    
96d1407
;; impl elimination
96d1407
96d1407
(declare impl_intro (! f1 formula
96d1407
                    (! f2 formula
96d1407
                    (! i1 (! u (th_holds f1) 
96d1407
                              (th_holds f2))
96d1407
                      (th_holds (impl f1 f2))))))
96d1407
96d1407
(declare impl_elim
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u1 (th_holds f1)
96d1407
  (! u2 (th_holds (impl f1 f2))  
96d1407
    (th_holds f2))))))
96d1407
    
96d1407
;; iff elimination
96d1407
96d1407
(declare iff_elim_1
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u1 (th_holds (iff f1 f2))
96d1407
    (th_holds (impl f1 f2))))))
96d1407
    
96d1407
(declare iff_elim_2
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u1 (th_holds (iff f1 f2))
96d1407
    (th_holds (impl f2 f1))))))
96d1407
96d1407
(declare not_iff_elim_1
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u1 (th_holds (not f1))
96d1407
  (! u2 (th_holds (not (iff f1 f2)))
96d1407
    (th_holds f2))))))
96d1407
96d1407
(declare not_iff_elim_2
96d1407
  (! f1 formula
96d1407
  (! f2 formula
96d1407
  (! u1 (th_holds f1)
96d1407
  (! u2 (th_holds (not (iff f1 f2)))
96d1407
    (th_holds (not f2)))))))
96d1407
96d1407
;; ite elimination
96d1407
96d1407
(declare ite_elim_1
96d1407
  (! a formula
96d1407
  (! b formula
96d1407
  (! c formula
96d1407
  (! u1 (th_holds a)
96d1407
  (! u2 (th_holds (ifte a b c))
96d1407
    (th_holds b)))))))
96d1407
    
96d1407
(declare ite_elim_2
96d1407
  (! a formula
96d1407
  (! b formula
96d1407
  (! c formula
96d1407
  (! u1 (th_holds (not a))
96d1407
  (! u2 (th_holds (ifte a b c))
96d1407
    (th_holds c)))))))
96d1407
    
96d1407
(declare ite_elim_3
96d1407
  (! a formula
96d1407
  (! b formula
96d1407
  (! c formula
96d1407
  (! u1 (th_holds (not b))
96d1407
  (! u2 (th_holds (ifte a b c))
96d1407
    (th_holds c)))))))
96d1407
    
96d1407
(declare ite_elim_2n
96d1407
  (! a formula
96d1407
  (! b formula
96d1407
  (! c formula
96d1407
  (! u1 (th_holds a)
96d1407
  (! u2 (th_holds (ifte (not a) b c))
96d1407
    (th_holds c)))))))
96d1407
96d1407
(declare not_ite_elim_1
96d1407
  (! a formula
96d1407
  (! b formula
96d1407
  (! c formula
96d1407
  (! u1 (th_holds a)
96d1407
  (! u2 (th_holds (not (ifte a b c)))
96d1407
    (th_holds (not b))))))))
96d1407
    
96d1407
(declare not_ite_elim_2
96d1407
  (! a formula
96d1407
  (! b formula
96d1407
  (! c formula
96d1407
  (! u1 (th_holds (not a))
96d1407
  (! u2 (th_holds (not (ifte a b c)))
96d1407
    (th_holds (not c))))))))
96d1407
    
96d1407
(declare not_ite_elim_3
96d1407
  (! a formula
96d1407
  (! b formula
96d1407
  (! c formula
96d1407
  (! u1 (th_holds b)
96d1407
  (! u2 (th_holds (not (ifte a b c)))
96d1407
    (th_holds (not c))))))))
96d1407
    
96d1407
(declare not_ite_elim_2n
96d1407
  (! a formula
96d1407
  (! b formula
96d1407
  (! c formula
96d1407
  (! u1 (th_holds a)
96d1407
  (! u2 (th_holds (not (ifte (not a) b c)))
96d1407
    (th_holds (not c))))))))