;; Jasper Berendsen
;; Julien Schmaltz
;; Radboud University Nijmegen
;; Nov. 10 2008
;; file: override_yices.yic
;; contains sources used to find models in our
;; proof of minimality of the axioms.
;; Paper: The axiomatization of overriding and update
;; FOSSACS 2009

(set-evidence! true) ;; to print a model
(set-verbosity! 2)   ;; force Yices to produce more output

(define-type domain ;; this defines the domain on which we try to find a model 
                    ;; to show Axiom 5 is independent we need 3 elements
	(scalar f0 f1 f2))

;; definition of types: operator, lemma, and axiom
(define-type operator (-> domain domain domain))
(define-type lemma (-> domain domain domain bool))
(define-type axiom (subtype (n::lemma) (= n n)))

;; our two operators over is our triangle (overriding) and min is our minus operator
(define over::operator)
(define min::operator)

;; our five axioms

(define idemp::axiom
  (lambda
    (f::domain g::domain h::domain)
    (= (over f f) f)
  )
)

(define empty::axiom
  (lambda
    (f::domain g::domain h::domain)
    (= (min f f) f0)
  )
)

(define swap::axiom
  (lambda
    (f::domain g::domain h::domain)
    (= (over (min f g) g) (over g f))
  )
)

(define drem::axiom
  (lambda
    (f::domain g::domain h::domain)
    (= (min f (min g h)) (over (min f g) (min f (min f h))))
  )
)

(define distr::axiom
  (lambda
    (f::domain g::domain h::domain)
    (= (min (over f g) h) (over (min f h) (min g h)))
  )
)

;; some technical functions to flatten quantifiers
(define allH::(-> lemma domain domain bool)
  (lambda (A::lemma f::domain g::domain)
    (and
      (A f g f0)
      (A f g f1)
      (A f g f2)
    )
  )
)

(define allG::(-> lemma domain bool)
  (lambda (A::lemma f::domain)
    (and
      (allH A f f0)
      (allH A f f1)
      (allH A f f2)
    )
  )
)

(define allF::(-> axiom bool)
  (lambda (A::lemma)
    (and
      (allG A f0)
      (allG A f1)
      (allG A f2)
    )
  )
)

;; proof of indepedence of Axiom 5
(push)
(assert (allF idemp)) ;;Ax 1 independence provable with 2 elements
(assert (allF empty)) ;;AX 2 independence provable with 2 elements
(assert (allF swap))  ;;Ax 3 independence provable with 2 elements
(assert (allF drem))  ;;Ax 4 independence provable with 3 elements; 
                      ;; of course needs more than 2 elements to prove indep
(assert (not (allF distr))) ;;Ax 5 independence provable with 3 elements; 
(check)
(pop)

;; to obtain the model
;; yices -e override_yices.yic
;;
;; the model
;;searching...
;;
;;sat
;;(= (over f0 f0) f0)
;;(= (over f1 f1) f1)
;;(= (over f2 f2) f2)
;;(= (min f0 f0) f0)
;;(= (min f1 f1) f0)
;;(= (min f2 f2) f0)
;;(= (min f0 f1) f0)
;;(= (over f0 f1) f1)
;;(= (over f1 f0) f1)
;;(= (min f0 f2) f0)
;;(= (over f0 f2) f2)
;;(= (over f2 f0) f2)
;;(= (min f1 f0) f1)
;;(= (min f1 f2) f1)
;;(= (over f1 f2) f0)
;;(= (over f2 f1) f0)
;;(= (min f2 f0) f2)
;;(= (min f2 f1) f2)