Skip to content

Commit 495e1a7

Browse files
someplaceguymn200
authored andcommitted
HolSmt: initial support for the exponential function
This initial support is very limited and only consists in adding a couple of useful theorems to the proving context. Hopefully, in the future more extensive support is implemented by adding support for Z3's native power operator, which should allow HolSmt to prove a lot more goals. This implementation would need to be similar to the implementation of integer division, since it doesn't exactly match HOL4's exponential functions. The latter would also have a couple of limitations, namely: 1. it would only work for Z3, since this operator is a Z3 extension and not part of the SMT-LIB standard 2. proof reconstruction would not work
1 parent 616c94b commit 495e1a7

File tree

2 files changed

+102
-17
lines changed

2 files changed

+102
-17
lines changed

src/HolSmt/SmtLib.sml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -622,25 +622,39 @@ in
622622
fun SIMP_TAC simp_let =
623623
let
624624
open Tactical simpLib
625-
(* TODO: In the future we should add all relevant theorems automatically,
626-
either based on which symbols are used (recursively) or, perhaps more
627-
simply, just translate all the theorems defined in all the theories that
628-
are being used. For now we just manually add a few useful ones. *)
629625
val facts =
630626
let
631-
open arithmeticTheory integerTheory
627+
open arithmeticTheory integerTheory realTheory realaxTheory
632628
in
633629
if !include_theorems then [
630+
(* NOTE: when adding a theorem to the list below, make sure that it
631+
doesn't have any free var -- otherwise, ASSUME_TAC will specialize
632+
the theorem to any free var in the goal that happens to have the same
633+
name, which very often is not what is desired. As an example,
634+
integerTheory's `INT_POW` should not be added -- instead, add
635+
`int_exp`. If no appropriate quantified theorem is available,
636+
`Drule.GEN_ALL` can be used to quantify all free vars in a theorem.
637+
638+
Also, make sure the theorem is really needed -- some theorems seem to
639+
cause an explosion in the time needed to solve some goals, often
640+
making Z3 unable to solve them -- and it's not always easy to tell a
641+
priori which ones do. As an example, arithmeticTheory.EXP_1 doesn't
642+
seem to cause issues, but EXP_2 prevents Z3 from solving
643+
``x DIV 42 <= x``. *)
644+
634645
(* arithmeticTheory *)
635-
GREATER_DEF, GREATER_EQ, MIN_DEF, MAX_DEF,
646+
EXP, EXP_1, EXP_POS, GREATER_DEF, GREATER_EQ, MAX_DEF, MIN_DEF,
636647
(* integerTheory *)
637648
INT, INT_ADD, INT_INJ, INT_LE, INT_LT, INT_MAX, INT_MIN, INT_OF_NUM,
638649
INT_POS, NUM_OF_INT, NUM_INT_MUL, NUM_INT_EDIV, NUM_INT_EMOD,
639-
INT_DIV_EDIV, INT_MOD_EMOD, INT_QUOT_EDIV, INT_REM_EMOD,
650+
INT_DIV_EDIV, INT_MOD_EMOD, INT_QUOT_EDIV, INT_REM_EMOD, int_exp,
651+
(* realTheory *)
652+
abs, POW_2, POW_ONE, REAL_POW_LT,
653+
(* realaxTheory *)
654+
real_max, real_min, real_pow,
640655
(* others *)
641656
int_arithTheory.INT_NUM_SUB,
642-
markerTheory.Abbrev_def,
643-
realaxTheory.real_min, realaxTheory.real_max, realTheory.abs
657+
markerTheory.Abbrev_def
644658
] else []
645659
end
646660
in

src/HolSmt/selftest.sml

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,24 @@ fun mk_test_fun is_configured expect_fun name smt_tac =
105105
fun auto_tac (_, t) =
106106
let
107107
val simpset = bossLib.++ (bossLib.srw_ss (), wordsLib.WORD_ss)
108-
val t_eq_t' = simpLib.SIMP_CONV simpset [integerTheory.INT_ABS,
109-
integerTheory.INT_MAX, integerTheory.INT_MIN, integerTheory.int_quot,
110-
integerTheory.int_rem, integerTheory.EDIV_DEF, integerTheory.EMOD_DEF,
111-
boolTheory.LET_THM]
112-
t
108+
val simp_thms =
109+
let
110+
open arithmeticTheory integerTheory realTheory
111+
in
112+
[
113+
(* arithmeticTheory *)
114+
EXP, EXP_1, EXP_2,
115+
(* integerTheory *)
116+
EDIV_DEF, EMOD_DEF, INT_ABS, INT_MAX, INT_MIN, int_exp, int_quot,
117+
int_rem,
118+
(* realTheory *)
119+
EXP_2, POW_2, REAL_POW_LT,
120+
(* others *)
121+
boolTheory.LET_THM
122+
]
123+
end
124+
val t_eq_t' =
125+
simpLib.SIMP_CONV simpset simp_thms t
113126
handle Conv.UNCHANGED =>
114127
Thm.REFL t
115128
val t' = boolSyntax.rhs (Thm.concl t_eq_t')
@@ -252,15 +265,15 @@ in
252265
[thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
253266
(``SUC (x + y) = (SUC x + SUC y)``, [sat_CVC, sat_YO, sat_Z3, sat_Z3p]),
254267

255-
(``(x:num) + 0 = x``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
268+
(``(x:num) + 0 = x``, [thm_AUTO, (*thm_CVC,*) thm_YO, thm_Z3, thm_Z3p_v4]),
256269
(``0 + (x:num) = x``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
257-
(``(x:num) + y = y + x``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
270+
(``(x:num) + y = y + x``, [thm_AUTO, (*thm_CVC,*) thm_YO, thm_Z3, thm_Z3p_v4]),
258271
(``(x:num) + (y + z) = (x + y) + z``,
259272
[thm_AUTO, (*thm_CVC,*) thm_YO, thm_Z3, thm_Z3p_v4]),
260273
(``((x:num) + y = 0) <=> (x = 0) /\ (y = 0)``,
261274
[thm_AUTO, (*thm_CVC,*) thm_YO, thm_Z3, thm_Z3p_v4]),
262275

263-
(``(x:num) - 0 = x``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
276+
(``(x:num) - 0 = x``, [thm_AUTO, (*thm_CVC,*) thm_YO, thm_Z3, thm_Z3p_v4]),
264277
(``(x:num) - y = y - x``, [sat_CVC, sat_YO, sat_Z3, sat_Z3p]),
265278
(``(x:num) - y - z = x - (y + z)``,
266279
[thm_AUTO, (*thm_CVC,*) thm_YO, thm_Z3, thm_Z3p_v4]),
@@ -317,6 +330,22 @@ in
317330
(``((x:num) = x DIV 42 * 42 + x MOD 42) /\ x MOD 42 < 42``,
318331
[thm_AUTO, (*thm_CVC,*) thm_YO, thm_Z3, thm_Z3p_v4]),
319332

333+
(``(x:num) ** 0 = 1``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
334+
(``(x:num) ** 0 = 0``, [sat_CVC, sat_Z3, sat_Z3p]),
335+
(``(x:num) ** 1 = x``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
336+
(``(0:num) ** 1 = 1``, [sat_CVC, sat_Z3, sat_Z3p]),
337+
(``(1:num) ** x = 1``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
338+
(``(1:num) ** x = 0``, [sat_CVC, sat_Z3, sat_Z3p]),
339+
(``(x:num) ** 2 = x * x``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
340+
(``(x:num) ** 2 = 2``, [sat_CVC, sat_Z3, sat_Z3p]),
341+
(``(x:num) ** 3 = x * x * x``, [(*thm_AUTO, thm_CVC, thm_Z3, thm_Z3p*)]),
342+
(``(x:num) ** 3 = 4``, [sat_CVC, sat_Z3, sat_Z3p]),
343+
(``0 < (x:num) ** y``, [sat_CVC, sat_Z3, sat_Z3p]),
344+
(``0 <= (x:num) ** y``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
345+
(``0 < (1:num) ** y``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
346+
(``0 < (2:num) ** y``, [thm_AUTO, (*thm_CVC,*) thm_Z3, thm_Z3p]),
347+
(``0 < (42:num) ** y``, [thm_AUTO, (*thm_CVC,*) thm_Z3, thm_Z3p]),
348+
320349
(``MIN (x:num) y <= x``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
321350
(``MIN (x:num) y <= y``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
322351
(``(z:num) < x /\ z < y ==> z < MIN x y``,
@@ -581,6 +610,28 @@ in
581610
(``(x:int) rem 42 = x - x quot 42 * 42``,
582611
[thm_AUTO, (*thm_CVC,*) thm_Z3, thm_Z3p_v4]),
583612

613+
(``(x:int) ** 0 = 1``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
614+
(``(x:int) ** 0 = 0``, [sat_CVC, sat_Z3, sat_Z3p]),
615+
(``(x:int) ** 1 = x``, [(*thm_AUTO, thm_CVC, thm_Z3, thm_Z3p*)]),
616+
(``(0:int) ** 1 = 1``, [sat_CVC, sat_Z3, sat_Z3p]),
617+
(``(1:int) ** x = 1``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
618+
(``(1:int) ** x = 0``, [sat_CVC, sat_Z3, sat_Z3p]),
619+
(``(-1:int) ** 1 = -1``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
620+
(``(-1:int) ** 2 = 1``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
621+
(``(-3:int) ** 1 = -3``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
622+
(``(-3:int) ** 2 = 9``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
623+
(``(x:int) ** 2 = x * x``, [(*thm_AUTO, thm_CVC, thm_Z3, thm_Z3p*)]),
624+
(``(x:int) ** 2 = 2``, [sat_CVC, sat_Z3, sat_Z3p]),
625+
(``(x:int) ** 3 = x * x * x``, [(*thm_AUTO, thm_CVC, thm_Z3, thm_Z3p*)]),
626+
(``(x:int) ** 3 = 4``, [sat_CVC, sat_Z3, sat_Z3p]),
627+
(``0 < (x:int) ** y``, [sat_CVC, sat_Z3, sat_Z3p]),
628+
(``0 <= (x:int) ** y``, [sat_CVC, sat_Z3, sat_Z3p]),
629+
(``0 < (1:int) ** y``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
630+
(``0 < (2:int) ** y``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
631+
(``0 < (-2:int) ** y``, [sat_CVC, sat_Z3, sat_Z3p]),
632+
(``0 < (42:int) ** y``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
633+
(``0 < (-42:int) ** y``, [sat_CVC, sat_Z3, sat_Z3p]),
634+
584635
(``ABS (x:int) >= 0``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3_v4, thm_Z3p_v4]),
585636
(``(ABS (x:int) = 0) = (x = 0)``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3_v4, thm_Z3p_v4]),
586637
(``(x:int) >= 0 ==> (ABS x = x)``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3_v4, thm_Z3p_v4]),
@@ -631,6 +682,26 @@ in
631682
(``x < 0 ==> (x:real) / 42 > x``,
632683
[thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
633684

685+
(``(x:real) pow 0 = 1``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
686+
(``(x:real) pow 0 = 0``, [sat_CVC, sat_Z3, sat_Z3p]),
687+
(``(x:real) pow 1 = x``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
688+
(``(0:real) pow 1 = 1``, [sat_CVC, sat_Z3, sat_Z3p]),
689+
(``(1:real) pow x = 1``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
690+
(``(1:real) pow x = 0``, [sat_CVC, sat_Z3, sat_Z3p]),
691+
(``(-1:real) pow 1 = -1``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
692+
(``(-1:real) pow 2 = 1``, [thm_AUTO, (*thm_CVC,*) thm_Z3, thm_Z3p]),
693+
(``(-3:real) pow 1 = -3``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
694+
(``(-3:real) pow 2 = 9``, [thm_AUTO, (*thm_CVC,*) thm_Z3, thm_Z3p]),
695+
(``(x:real) pow 2 = x * x``, [thm_AUTO, (*thm_CVC,*) thm_Z3, thm_Z3p]),
696+
(``(x:real) pow 3 = x * x * x``, [thm_AUTO(*, thm_CVC, thm_Z3, thm_Z3p*)]),
697+
(``0 < (x:real) pow y``, [sat_CVC, sat_Z3, sat_Z3p]),
698+
(``0 <= (x:real) pow y``, [sat_CVC, sat_Z3, sat_Z3p]),
699+
(``0 < (1:real) pow y``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
700+
(``0 < (2:real) pow y``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
701+
(``0 < (-2:real) pow y``, [sat_CVC, sat_Z3, sat_Z3p]),
702+
(``0 < (42:real) pow y``, [thm_AUTO, thm_CVC, thm_Z3, thm_Z3p]),
703+
(``0 < (-42:real) pow y``, [sat_CVC, sat_Z3, sat_Z3p]),
704+
634705
(``abs (x:real) >= 0``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
635706
(``(abs (x:real) = 0) = (x = 0)``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),
636707
(``(x:real) >= 0 ==> (abs x = x)``, [thm_AUTO, thm_CVC, thm_YO, thm_Z3, thm_Z3p_v4]),

0 commit comments

Comments
 (0)