src/Pure/Isar/rule_cases.ML
changeset 55639 e4e8cbd9d780
parent 54742 7a86358a3c0b
child 56231 b98813774a63
equal deleted inserted replaced
55638:9b1805ff3aae 55639:e4e8cbd9d780
   231 
   231 
   232 fun lookup_consumes th =
   232 fun lookup_consumes th =
   233   (case AList.lookup (op =) (Thm.get_tags th) consumes_tagN of
   233   (case AList.lookup (op =) (Thm.get_tags th) consumes_tagN of
   234     NONE => NONE
   234     NONE => NONE
   235   | SOME s =>
   235   | SOME s =>
   236       (case Lexicon.read_nat s of SOME n => SOME n
   236       (case Lexicon.read_nat s of
       
   237         SOME n => SOME n
   237       | _ => raise THM ("Malformed 'consumes' tag of theorem", 0, [th])));
   238       | _ => raise THM ("Malformed 'consumes' tag of theorem", 0, [th])));
   238 
   239 
   239 fun get_consumes th = the_default 0 (lookup_consumes th);
   240 fun get_consumes th = the_default 0 (lookup_consumes th);
   240 
   241 
   241 fun put_consumes NONE th = th
   242 fun put_consumes NONE th = th
   260 
   261 
   261 fun lookup_constraints th =
   262 fun lookup_constraints th =
   262   (case AList.lookup (op =) (Thm.get_tags th) constraints_tagN of
   263   (case AList.lookup (op =) (Thm.get_tags th) constraints_tagN of
   263     NONE => NONE
   264     NONE => NONE
   264   | SOME s =>
   265   | SOME s =>
   265       (case Lexicon.read_nat s of SOME n => SOME n
   266       (case Lexicon.read_nat s of
       
   267         SOME n => SOME n
   266       | _ => raise THM ("Malformed 'constraints' tag of theorem", 0, [th])));
   268       | _ => raise THM ("Malformed 'constraints' tag of theorem", 0, [th])));
   267 
   269 
   268 fun get_constraints th = the_default 0 (lookup_constraints th);
   270 fun get_constraints th = the_default 0 (lookup_constraints th);
   269 
   271 
   270 fun put_constraints NONE th = th
   272 fun put_constraints NONE th = th
   339   these (get_first (get_case_concl name) (Thm.get_tags th));
   341   these (get_first (get_case_concl name) (Thm.get_tags th));
   340 
   342 
   341 fun save_case_concls th =
   343 fun save_case_concls th =
   342   let val concls = Thm.get_tags th |> map_filter
   344   let val concls = Thm.get_tags th |> map_filter
   343     (fn (a, b) =>
   345     (fn (a, b) =>
   344       if a = case_concl_tagN then (case explode_args b of c :: cs => SOME (c, cs) | _ => NONE)
   346       if a = case_concl_tagN
       
   347       then (case explode_args b of c :: cs => SOME (c, cs) | _ => NONE)
   345       else NONE)
   348       else NONE)
   346   in fold add_case_concl concls end;
   349   in fold add_case_concl concls end;
   347 
   350 
   348 fun case_conclusion concl = Thm.mixed_attribute (apsnd (add_case_concl concl));
   351 fun case_conclusion concl = Thm.mixed_attribute (apsnd (add_case_concl concl));
   349 
   352 
   383     val n = get_consumes th;
   386     val n = get_consumes th;
   384     val cases =
   387     val cases =
   385       (case lookup_case_names th of
   388       (case lookup_case_names th of
   386         NONE => map (rpair [] o Library.string_of_int) (1 upto (Thm.nprems_of th - n))
   389         NONE => map (rpair [] o Library.string_of_int) (1 upto (Thm.nprems_of th - n))
   387       | SOME names => map (fn name => (name, get_case_concls th name)) names);
   390       | SOME names => map (fn name => (name, get_case_concls th name)) names);
   388     val cases_hyps = (case lookup_cases_hyp_names th of
   391     val cases_hyps =
       
   392       (case lookup_cases_hyp_names th of
   389         NONE => replicate (length cases) []
   393         NONE => replicate (length cases) []
   390       | SOME names => names);
   394       | SOME names => names);
   391     fun regroup ((name,concls),hyps) = ((name,hyps),concls)
   395     fun regroup ((name,concls),hyps) = ((name,hyps),concls)
   392   in (map regroup (cases ~~ cases_hyps), n) end;
   396   in (map regroup (cases ~~ cases_hyps), n) end;
   393 
   397