Closed someplaceguy closed 2 months ago
Added one commit to update the HolSmt documentation regarding recent improvements.
Can you put the Euclidean div and mod constants (perhaps call them ediv
and emod
) into integerScript.sml
please?
Can you put the Euclidean div and mod constants (perhaps call them
ediv
andemod
) intointegerScript.sml
please?
Sure, but how would you like me to do that? Just add those definitions to integerScript.sml
as they are (except for the renaming)? Anything else?
For reference, I took a look at how int_quot
and int_rem
are defined and there seems to be a lot going on there, e.g.:
int_quot
is actually defined based on the natural numbers (instead of being defined based on int_div
like I did). This would be easy enough to do.int_quot
(and int_div
) are constant specifications instead of constant definitions (which require proving a theorem, although that seems quite doable). Should I use constant specifications as well?quot
-related theorems are proved. I guess I could try to prove similar ones, although it would take me some time... However, INT_QUOT_UNIQUE
seems incredibly daunting to prove...rem
also has quite a few theorems and a few daunting ones as well...*_REDUCE
theorems but not the INT_{QUOT,REM}_CALCULATE
ones.intSyntax.{sig,sml}
(this seems trivial to add).omega
and cooper
decision procedures, although I can't even find the string "quot"
in there? (And even if I did, I doubt I'd be able to figure out how to add support for ediv
and emod
there...).So, which of the above should I do?
Can you put the Euclidean div and mod constants (perhaps call them
ediv
andemod
) intointegerScript.sml
please?Sure, but how would you like me to do that? Just add those definitions to
integerScript.sml
as they are (except for the renaming)? Anything else?For reference, I took a look at how
int_quot
andint_rem
are defined and there seems to be a lot going on there, e.g.:
int_quot
is actually defined based on the natural numbers (instead of being defined based onint_div
like I did). This would be easy enough to do.int_quot
(andint_div
) are constant specifications instead of constant definitions (which require proving a theorem, although that seems quite doable). Should I use constant specifications as well?- Infix constants are also defined, although this seems trivial.
- Some
quot
-related theorems are proved. I guess I could try to prove similar ones, although it would take me some time... However,INT_QUOT_UNIQUE
seems incredibly daunting to prove...rem
also has quite a few theorems and a few daunting ones as well...- Furthermore, these two operators also have theorems used for rewrites. I think I understand the
*_REDUCE
theorems but not theINT_{QUOT,REM}_CALCULATE
ones.- These operators also have syntax manipulation functions defined in
intSyntax.{sig,sml}
(this seems trivial to add).- For completion I assume simplification rules are added somewhere, although I can't figure out where?
- And then presumably these operators have support in the
omega
andcooper
decision procedures, although I can't even find the string"quot"
in there? (And even if I did, I doubt I'd be able to figure out how to add support forediv
andemod
there...).So, which of the above should I do?
I think @mn200 simply meant that you can move the definitions of smtdiv
and smtmod
(renamed to ediv
and emod
) and related theorems (from SMT_NUM_ADD to SMT_INT_REM), i.e. all you added into HolSmtScript.sml
, to integerScript.sml
. In this way, the definitions and theorems can be reused by potential other users in the future.
@binghe has it right; what you have already is a good starting point for future work, and it would be better to have that work happen in integerTheory
.
Added 7 more commits:
P = P
and then not forget to discharge it, in which case lemma
might require the hypothesis to be there.integerTheory
, as well as the theorems that had been added to HolSmt, as requested by @binghe and @mn200.integerTheory
's definition of ediv
and emod
, as well as the theorems that were moved there, thus removing the definitions and theorems from HolSmt.quot
and rem
due to #1207.quot
and rem
, all with Z3 proof replay enabled. Perplexingly, I had forgotten to add these.thm_AUTO
, which help make advances in proving the last self-test but do not yet allow it to succeed.Note: I wasn't sure what to name the newly added definitions and theorems in integerTheory
, nor where to put them exactly, so let me know if you'd like me to make any further changes.
Thanks!
Added one more commit which ignores indices in rewrite
proof rules instead of failing to parse the proof certificates with an error. This way we don't fail to parse proof certificates in case e.g. a future version of Z3 adds an index to these proof rules.
Added one more commit which partially reverts a previous one, which had added a change that was actually unnecessary.
I realized this was unnecessary after thinking about it (and realizing it didn't make much sense), however I don't understand why I introduced that change in the first place, since I cannot reproduce those test failures and nothing relevant was changed in the mean time...
Added 2 more commits, which fix issues when parsing SMT-LIB commands.
This part of the parser is used only for importing SMT-LIB problems into HOL4, which is useful for testing HolSmt but is not the main use case of HolSmt.
Added one more commit with a simple fix, this time fixing an error when parsing some Z3 proof certificates.
Added one commit to remove the workaround for #1203, since it's no longer necessary. Thanks @mn200!
Thanks for all of this work!
Hi!
This PR implements support for
DIV
,MOD
,$/
,$%
,quot
andrem
, i.e. all div and mod operators fornum
andint
. It also enables proof replay for all the self-tests that contained these operators. No changes were made outside HolSmt.In total, 78 more self-tests are now passing (with Z3 v4 proof replay). In fact, I believe all arithmetic test cases are now passing, including with proof replay, with the exception of the word tests (and one which I added and mention below).
The support for the div and mod operators were implemented using the following approach:
HolSmtTheory
calledsmtdiv
andsmtmod
, which implement the semantics of SMT-LIB's integer division and modulo operators.smtdiv
was defined based on$/
andsmtmod
based on$%
for simplicity.selftests.sml
which verifies thatsmtdiv
andsmtmod
exactly match the SMT-LIB definition.selftests.sml
).HolSmtTheory
which define HOL4's div and mod operators in terms ofsmtdiv
andsmtmod
(these are easier to prove). These theorems are now added to the proving context by default, so that SMT solvers can translate HOL4's div and mod operators into the equivalent SMT-LIB div and mod operators which they natively support.smtdiv
andsmtmod
.smtdiv
andsmtmod
(by rewriting with their definitions into equivalent HOL4$/
and$%
operations).This PR also implements the following:
let ... and ... in ...
, i.e. the one with parallel definitions, into the SMT-LIB language. This translation had never actually worked before, onlylet ... ; ... in ...
was working properly.COOPER_PROVE
is much slower thanARITH_PROVE
in some cases, so now we try the latter before falling back to the former.generalize_ite
procedure was removed, as it seems to be unnecessary and was causing some arithmetic proof steps to fail.smtdiv
andsmtmod
.th_lemma_arith
andrewrite
arithmetic proof handlers need the above fixes, these arithmetic proving procedures now use a common implementation.P = P
, so it's easy to discharge them ourselves.iff-false
Z3 proof inference rule.I'm happy with the results, although I was a bit surprised by how hard it was to fix proof replay for these tests. I was expecting Z3 to throw more curve-balls, but this time Z3 did not give me much trouble.
Instead, the major problems were the limitations in the HOL4 integer arithmetic decision procedures, especially #1207. I implemented some workarounds (i.e. I try to prove the goals using some additional tactics, including arithmetic simplifications) but I don't expect these to be reliable and in fact, if I change some theorems around a bit I do encounter some linear arithmetic steps which HOL4 cannot prove automatically even with my workarounds.
Anyway, I think this concludes my work for the near future, as the next issues to tackle are quite hard to solve.
Thanks!
cc @tjark