From 306721649f0963ab225deb8d5670cfe196bb360d Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Tue, 21 Jul 2020 16:28:05 +0200 Subject: 1. Bugfix: implicits now properly name schematic variables. Fixes problems caused by variable name clashes. 2. reduce method now more principled: restricts to repeating on first subgoal. 3. An example declarative proof in Equivalence.thy. --- spartan/core/Spartan.thy | 18 +++++++++++------- spartan/core/implicits.ML | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 16 deletions(-) (limited to 'spartan/core') diff --git a/spartan/core/Spartan.thy b/spartan/core/Spartan.thy index a4ad300..fa6148f 100644 --- a/spartan/core/Spartan.thy +++ b/spartan/core/Spartan.thy @@ -52,7 +52,7 @@ paragraph \ typedecl o -judgment has_type :: \o \ o \ prop\ ("(2_:/ _)" 999) +consts has_type :: \o \ o \ prop\ ("(2_:/ _)" 999) text \Type annotations for type-checking and inference.\ @@ -232,6 +232,10 @@ method_setup rule = \Attrib.thms >> (fn ths => K (CONTEXT_METHOD ( CHEADGOAL o SIDE_CONDS (rule_ctac ths))))\ +method_setup rules = + \Attrib.thms >> (fn ths => K (CONTEXT_METHOD ( + CREPEAT o CHEADGOAL o SIDE_CONDS (rule_ctac ths))))\ + method_setup dest = \Scan.lift (Scan.option (Args.parens Parse.int)) -- Attrib.thms >> (fn (n_opt, ths) => K (CONTEXT_METHOD ( @@ -255,6 +259,8 @@ method_setup cases = \Args.term >> (fn tm => K (CONTEXT_METHOD ( CHEADGOAL o SIDE_CONDS (cases_ctac tm))))\ +method facts = fact+ + subsection \Reflexivity\ @@ -310,7 +316,8 @@ setup \map_theory_simpset (fn ctxt => ctxt addSolver (mk_solver "" (fn ctxt' => NO_CONTEXT_TACTIC ctxt' o Types.check_infer (Simplifier.prems_of ctxt'))))\ -method reduce uses add = changed \((simp add: comp add | sub comp); typechk?)+\ +method reduce uses add = + changed \repeat_new \(simp add: comp add | sub comp); typechk?\\ subsection \Implicits\ @@ -327,10 +334,7 @@ ML_file \implicits.ML\ attribute_setup implicit = \Scan.succeed Implicits.implicit_defs_attr\ -ML \ -val _ = Context.>> - (Syntax_Phases.term_check 1 "" (fn ctxt => map (Implicits.make_holes ctxt))) -\ +ML \val _ = Context.>> (Syntax_Phases.term_check 1 "" Implicits.make_holes)\ text \Automatically insert inhabitation judgments where needed:\ @@ -488,7 +492,7 @@ lemma snd_type [typechk]: lemma snd_comp [comp]: assumes "a: A" "b: B a" "A: U i" "\x. x: A \ B x: U i" shows "snd A B \ b" - unfolding snd_def by reduce+ + unfolding snd_def by reduce subsection \Notation\ diff --git a/spartan/core/implicits.ML b/spartan/core/implicits.ML index 4d73c8d..ab64b0f 100644 --- a/spartan/core/implicits.ML +++ b/spartan/core/implicits.ML @@ -3,7 +3,7 @@ sig val implicit_defs: Proof.context -> (term * term) Symtab.table val implicit_defs_attr: attribute -val make_holes: Proof.context -> term -> term +val make_holes: Proof.context -> term list -> term list end = struct @@ -25,16 +25,15 @@ val implicit_defs_attr = Thm.declaration_attribute (fn th => Defs.map (Symtab.update (Term.term_name head, (head, def'))) end) -fun make_holes ctxt = +fun make_holes_single ctxt tm name_ctxt = let fun iarg_to_hole (Const (\<^const_name>\iarg\, T)) = Const (\<^const_name>\hole\, T) | iarg_to_hole t = t fun expand head args = - let - fun betapplys (head', args') = - Term.betapplys (map_aterms iarg_to_hole head', args') + let fun betapplys (head', args') = + Term.betapplys (map_aterms iarg_to_hole head', args') in case head of Abs (x, T, t) => @@ -66,13 +65,17 @@ fun make_holes ctxt = in subst t (take n vs) Ts $ subst u (drop n vs) Ts end | subst t _ _ = t - val vars = map (fn n => Var ((n, 0), dummyT)) - (Name.invent (Variable.names_of ctxt) "*" (count t)) + val names = Name.invent name_ctxt "*" (count t) + val vars = map (fn n => Var ((n, 0), dummyT)) names in - subst t vars [] + (subst t vars [], fold Name.declare names name_ctxt) end in - Lib.traverse_term expand #> holes_to_vars + holes_to_vars (Lib.traverse_term expand tm) end +fun make_holes ctxt tms = #1 + (fold_map (make_holes_single ctxt) tms (Variable.names_of ctxt)) + + end -- cgit v1.2.3