OCamlPro / alt-ergo

OCamlPro public development repository for Alt-Ergo
https://alt-ergo.ocamlpro.com/
Other
132 stars 33 forks source link

Can't prove "true" in smtlib format? #461

Closed Elarnon closed 3 years ago

Elarnon commented 3 years ago

When given the following smtlib file:

$ cat true.smtlib2
(assert true)
(check-sat)

AltErgo 2.4.0 answers:

; File "true.smtlib2", line 2, characters 1-12: I don't know (0.0074) (0 steps) (goal g_1)

unknown

which seems… quite cautious. What is surprising is that when given (what I believe is) the same trivial goal in its native format:

$ cat true.altergo
goal g: true

I get:

File "true.altergo", line 1, characters 9-13: Valid (0.0078) (0 steps) (goal g)

This also reproduces on the online version and looks like a bug? I tried a couple examples but couldn't get AltErgo to answer "Valid" on any files in smtlib format; is this expected?

Stevendeo commented 3 years ago

Hello,

This surprisingly is not a bug. When Alt-Ergo attempts to prove a '.altergo' file, it will attempt to validate the goals. true is true, which is fine. Alt-Ergo actually works on SMT formulas by trying to prove their negation. IKeep in mind that Alt-Ergo will never (for now) answer SAT. It only can return Unsat (which corresponds to Valid) or Unknown. If the negation is true, the formula is Unsat, hence Valid.

Try

$ cat true.smtlib2
(assert false)
(check-sat)

It should return "Valid".

mattiasdrp commented 3 years ago

Hi, I'm not working on this project anymore but here's why this is not an issue:

When proving a formula F in smt-lib2 format, Alt-Ergo will try to prove that the formula F is unsat:

When proving a formula F in native format, Alt-Ergo will try to prove that it's negation not F is unsat:

In your example, you're trying to check the satisfiability of true. In smt-lib2, Alt-Ergo will check that true is not unsat, it will succeed but since there's nothing as of now to tell Alt-Ergo that there are no quantifiers, it will just answer "unknown" In native format, Alt-Ergo will check that the negation of true is not unsat but false is inherently unsat so the goal is valid

It should be clear at this point that if a solver answers "sat" when dealing with quantifiers you should be cautious about the result, it may be really sat or it may be sat at this point

Now, if you want to go further:

(declare-fun p () Bool)
(assert (or p (not p)))
(check-sat)

will return:

; File "test.smt2", line 3, characters 1-12: I don't know (0.0015) (0 steps) (goal g_1) unknown

When

logic p:bool
goal g: p or (not p)

will return:

File "test.ae", line 2, characters 9-21: Valid (0.0016) (0 steps) (goal g)

Because the negation of p or (not p) is (not p) and p, this is unsat so the original formula is valid

But if you write

logic p:bool
goal g: p and (not p)

you will get:

File "test.ae", line 2, characters 9-22: I don't know (0.0000) (0 steps) (goal g)

Because the negation of p and (not p) is (not p) or p which is not unsat but AE can't be sure it's valid, sat or not yet proven unsat so the honest answer is unknown.

This is a bit complicated but it has to do with the undecidability of first-order logic with quantifiers.

Summary: if you want to prove that a formula is valid in smt-lib format, check that it's negation is unsat.

Example, if I want to prove that for all x and y, x <= y or x >= y, if I check this formula directly:

(declare-fun x () Int)
(declare-fun y () Int)
(assert (or (<= x y) (>= x y)))
(check-sat)

will return

; File "test.smt2", line 4, characters 1-12: I don't know (0.0021) (2 steps) (goal g_1) unknown

But if I write instead

(declare-fun x () Int)
(declare-fun y () Int)
(assert (and (> x y) (< x y)))
(check-sat)

I will have:

; File "test.smt2", line 3, characters 1-31: Inconsistent assumption (0.0016) (1 steps) ; File "test.smt2", line 4, characters 1-12: Valid (0.0017) (1 steps) (goal g_1) unsat

(your context is now filled with an unsat formula so the following (check-sat) will always return unsat)

Elarnon commented 3 years ago

Right, I did not think that Alt-Ergo would be performing automatic negations in one format but not the other, although it does seem obvious in retrospect. I guess this is just Alt-Ergo not producing models, then. Thanks for the detailed explanation!

mattiasdrp commented 3 years ago

You're welcome :-)

mattiasdrp commented 3 years ago

@Elarnon If you want to try models in Alt-Ergo, check the models branch by the way ;-)