1

I wanted to create a SMT sequence, such that I have a total ordering which should be complete.

example 1: a < b and b < c should be satisfiable

example 2: a < b and c < d should be unsatisfiable. By adding b < c we will get satisfiability.

Does anyone have any idea if this is even possible in general? So far I tried the following:

 (declare-fun my_rel (Int Int) (Bool))
 (assert (forall ((i Int)(j Int)) (implies (my_rel i j) (> i j))))
 (declare-const a Int)
 (declare-const b Int)
 (declare-const c Int)
 (declare-const d Int)
 (assert (my_rel a b))
 (assert (my_rel c d))
 (check-sat)

This should return UNSAT. By adding (assert (my_rel b c)) it should satisfy.

paubo147
  • 748
  • 4
  • 8

1 Answers1

1

I believe that what you want is a way to check if a transitive order over a finite set of elements x_1 ... x_n must be or is entailed to be complete and total because of a set of user assertions P about the order.

The < relation appears to be implicitly transitive in your example. The easy way to hack together an implicitly transitive binary relation is to use an uninterpreted function to embed any arbitrary domain into a totally ordered interpreted domain. Make sure the uninterpreted function added for this purpose appears only in this "embed into an order" sense.

(declare-fun foo (U) (Int))
(define-fun my_rel_strict ((i U) (j U)) (Bool) (> (foo i)  (foo j)))
(define-fun my_rel_nonstrict ((i U) (j U)) (Bool)
     (or (= (foo i) (foo j)) (my_rel_strict i j))

Both of the my_rel relations will transitive and my_rel_strict has the totality condition (either (my_real_nonstrict i j) or (my_rel_nonstrict j i) holds). (See http://en.wikipedia.org/wiki/Total_order) Neither is a total order as my_rel does not have antisymmetry. To avoid potential problems, the cardinality of the domain should be at least that of the codomain (or both are infinite). (The encoding for my_rel_nonstrict is not great. I'd try <= in practice.)

Next I believe what you want is an entailment check. Given a set of assertions P, does the user defined transitive order (which I now write as <) have to be total? We invent a formula total(x_1 ... x_n) for a finite set of elements:

total(x_1 ... x_n) = (and_{for all i,j} (or (< x_i x_j) (= x_i x_j) (> x_i x_j)))

(Not a very pleasant encoding of total, but an encoding all the same.) To check that P entails total(...), we query the smt solver with:

(assert P) (assert (not total(...)))
; You may also need (assert (distinct x_1 ... x_n))

If it is unsatisfiable the entailment holds. If it is satisfiable, the entailment has a counter example and does not hold.

Orders can be tricky to encode so my advice may not apply to your application. (Also take the above with a grain of salt. I am not 100% about it.)

Tim
  • 1,008
  • 5
  • 13