refactor(library/init/meta/smt): use default value for config structures

This commit is contained in:
Leonardo de Moura 2017-01-23 14:18:06 -08:00
parent 1d98192071
commit 6d12de6339
14 changed files with 31 additions and 50 deletions

View file

@ -8,20 +8,16 @@ import init.meta.tactic init.meta.set_get_option_tactics
structure cc_config :=
/- If tt, congruence closure will treat implicit instance arguments as constants. -/
(ignore_instances : bool)
(ignore_instances : bool := tt)
/- If tt, congruence closure modulo AC. -/
(ac : bool)
(ac : bool := tt)
/- If ho_fns is (some fns), then full (and more expensive) support for higher-order functions is
*only* considered for the functions in fns and local functions. The performance overhead is described in the paper
"Congruence Closure in Intensional Type Theory". If ho_fns is none, then full support is provided
for *all* constants. -/
(ho_fns : option (list name))
(ho_fns : option (list name) := some [])
/- If true, then use excluded middle -/
(em : bool)
def default_cc_config : cc_config :=
{ignore_instances := tt, ac := tt, ho_fns := some [], em := tt}
(em : bool := tt)
/- Congruence closure state -/
meta constant cc_state : Type
@ -52,10 +48,10 @@ meta constant cc_state.proof_for_false : cc_state → tactic expr
namespace cc_state
meta def mk : cc_state :=
cc_state.mk_core default_cc_config
cc_state.mk_core {}
meta def mk_using_hs : tactic cc_state :=
cc_state.mk_using_hs_core default_cc_config
cc_state.mk_using_hs_core {}
meta def roots (s : cc_state) : list expr :=
cc_state.roots_core s tt
@ -104,7 +100,7 @@ do intros, s ← cc_state.mk_using_hs_core cfg, t ← target, s ← s^.internali
}
meta def tactic.cc : tactic unit :=
tactic.cc_core default_cc_config
tactic.cc_core {}
meta def tactic.cc_dbg_core (cfg : cc_config) : tactic unit :=
save_options $
@ -112,7 +108,7 @@ save_options $
>> tactic.cc_core cfg
meta def tactic.cc_dbg : tactic unit :=
tactic.cc_dbg_core default_cc_config
tactic.cc_dbg_core {}
meta def tactic.ac_refl : tactic unit :=
do (lhs, rhs) ← target >>= match_eq,

View file

@ -140,10 +140,7 @@ do
caching_user_attribute.get_cache attr
structure ematch_config :=
(max_instances : nat)
def default_ematch_config : ematch_config :=
{max_instances := 10000}
(max_instances : nat := 10000)
/- Ematching -/
meta constant ematch_state : Type

View file

@ -26,14 +26,9 @@ run_command mk_hinst_lemma_attr_set `ematch [] [`ematch_lhs]
is used during preprocessing.
-/
structure smt_pre_config :=
(simp_attr : name)
(max_steps : nat)
(zeta : bool)
def default_smt_pre_config : smt_pre_config :=
{ simp_attr := `pre_smt,
max_steps := 1000000,
zeta := ff }
(simp_attr : name := `pre_smt)
(max_steps : nat := 1000000)
(zeta : bool := ff)
/--
Configuration for the smt_state object.
@ -41,16 +36,10 @@ Configuration for the smt_state object.
- em_attr: is the attribute name for the hinst_lemmas
that are used for ematching -/
structure smt_config :=
(cc_cfg : cc_config)
(em_cfg : ematch_config)
(pre_cfg : smt_pre_config)
(em_attr : name)
def default_smt_config : smt_config :=
{cc_cfg := default_cc_config,
em_cfg := default_ematch_config,
pre_cfg := default_smt_pre_config,
em_attr := `ematch}
(cc_cfg : cc_config := {})
(em_cfg : ematch_config := {})
(pre_cfg : smt_pre_config := {})
(em_attr : name := `ematch)
meta def smt_config.set_classical (c : smt_config) (b : bool) : smt_config :=
{c with cc_cfg := { (c^.cc_cfg) with em := b}}
@ -203,7 +192,7 @@ private meta def mk_smt_goals_for (cfg : smt_config) : list expr → list smt_go
meta def slift {α : Type} (t : tactic α) : smt_tactic α :=
λ ss, do
_::sgs ← return ss | fail "slift tactic failed, there no smt goals to be solved",
cfg ← return default_smt_config, -- TODO(Leo): use get_config
cfg ← return {smt_config .}, -- TODO(Leo): use get_config
tg::tgs ← tactic.get_goals | tactic.failed,
tactic.set_goals [tg], a ← t,
new_tgs ← tactic.get_goals,
@ -381,4 +370,4 @@ do ss ← smt_state.mk cfg,
return ()
meta def using_smt : smt_tactic unit → tactic unit :=
using_smt_core default_smt_config
using_smt_core {}

View file

@ -338,7 +338,7 @@ do passive ← flip monad.lift state_t.read $ λst, st^.passive, for' passive^.t
return ()
def super_cc_config : cc_config :=
{ default_cc_config with em := ff }
{ em := ff }
meta def do_sat_run : prover (option expr) :=
do sat_result ← in_sat_solver $ cdcl.run (cdcl.theory_solver_of_tactic $ using_smt $ return ()),

View file

@ -12,7 +12,7 @@ meta def add_insts : list (expr × expr) → tactic unit
meta def ematch_test (h : name) (e : expr) : tactic unit :=
do cc ← cc_state.mk_using_hs,
ems ← return $ ematch_state.mk default_ematch_config,
ems ← return $ ematch_state.mk {},
hlemma ← hinst_lemma.mk_from_decl h,
(r, cc, ems) ← ematch cc ems hlemma e,
add_insts r

View file

@ -17,7 +17,7 @@ meta def internalize_hs : list expr → ematch_state → tactic ematch_state
meta def ematch_test (h : name) : tactic unit :=
do cc ← cc_state.mk_using_hs,
ctx ← local_context,
ems ← internalize_hs ctx (ematch_state.mk default_ematch_config),
ems ← internalize_hs ctx (ematch_state.mk {}),
tgt ← target,
ems ← ems^.internalize tgt,
hlemma ← hinst_lemma.mk_from_decl h,

View file

@ -28,7 +28,7 @@ begin [smt] -- the default configuration is classical
end
lemma ex5 (p q : Prop) [decidable p] : p q → p ¬q → ¬p q → ¬p ¬q → false :=
begin [smt] with default_smt_config^.set_classical ff,
begin [smt] with {smt_config .}^.set_classical ff,
intros,
by_cases p -- will fail if p is not decidable
end
@ -42,13 +42,13 @@ begin [smt] -- the default configuration is classical
end
lemma ex7 (p q : Prop) [decidable p] : p q → p ¬q → ¬p q → p ∧ q :=
begin [smt] with default_smt_config^.set_classical ff,
begin [smt] with {smt_config .}^.set_classical ff,
intros,
by_cases p -- will fail if p is not decidable
end
lemma ex8 (p q : Prop) [decidable p] [decidable q] : p q → p ¬q → ¬p q → p ∧ q :=
begin [smt] with default_smt_config^.set_classical ff,
begin [smt] with {smt_config .}^.set_classical ff,
intros,
by_contradiction, -- will fail if p or q is not decidable
trace_state,

View file

@ -4,7 +4,7 @@ variables {α : Type u}
open smt_tactic
meta def no_ac : smt_config :=
{ default_smt_config with cc_cfg := { default_cc_config with ac := ff }}
{ cc_cfg := { ac := ff }}
meta def blast : tactic unit :=
using_smt_core no_ac $ intros >> repeat (ematch >> try close)

View file

@ -18,7 +18,7 @@ lemma app_nil_right {n : nat} (v : vector α n) : app v nil == v :=
begin induction v, reflexivity, {[smt] ematch_using [app, add_comm, zero_add, add_zero] }, end
def smt_cfg : smt_config :=
{ default_smt_config with cc_cfg := {default_cc_config with ac := ff}}
{ cc_cfg := {ac := ff}}
lemma app_assoc {n₁ n₂ n₃ : nat} (v₁ : vector α n₁) (v₂ : vector α n₂) (v₃ : vector α n₃) :
app v₁ (app v₂ v₃) == app (app v₁ v₂) v₃ :=

View file

@ -3,7 +3,7 @@ add_comm
open smt_tactic
meta def no_ac : smt_config :=
{ default_smt_config with cc_cfg := { default_cc_config with ac := ff }}
{ cc_cfg := { ac := ff }}
lemma ex {α : Type} [field α] (a b : α) : a + b = b + a :=
begin [smt] with no_ac,

0
tests/lean/run/test_single.sh Normal file → Executable file
View file

View file

@ -11,11 +11,8 @@ meta def fail_if_success {α : Type} (t : smt_tactic α) : smt_tactic unit :=
| exception .(α × smt_state) _ _ _ := success ((), ss) ts
end
def my_pre_config : smt_pre_config :=
{ default_smt_pre_config with zeta := tt }
def my_smt_config : smt_config :=
{ default_smt_config with pre_cfg := my_pre_config }
{ pre_cfg := { zeta := tt } }
lemma ex2 : let x := 1 in ∀ y, x = y → y = 1 :=
by using_smt_core my_smt_config $ smt_tactic.intros >> fail_if_success (get_local `x) >> return ()

View file

@ -1,3 +1,5 @@
def default_smt_pre_config : smt_pre_config := {}
def my_pre_config1 : smt_pre_config :=
{ default_smt_pre_config . zeta := tt }

View file

@ -1 +1 @@
structure_instance_bug2.lean:2:0: error: invalid structure instance, 'default_smt_pre_config' is not the name of a structure type
structure_instance_bug2.lean:4:0: error: invalid structure instance, 'default_smt_pre_config' is not the name of a structure type