216 | dups => error ("Inconsistent sort constraints for " ^ commas dups)) |
216 | dups => error ("Inconsistent sort constraints for " ^ commas dups)) |
217 end; |
217 end; |
218 |
218 |
219 (* arrange data entries *) |
219 (* arrange data entries *) |
220 |
220 |
221 fun make_dt_info alt_names descr sorts inducts reccomb_names rec_thms |
221 fun make_dt_info alt_names descr sorts induct inducts rec_names rec_rewrites |
222 ((((((((((i, (_, (tname, _, _))), case_name), case_thms), |
222 ((((((((((i, (_, (tname, _, _))), case_name), case_rewrites), |
223 exhaust_thm), distinct_thm), inject), splits), nchotomy), case_cong), weak_case_cong) = |
223 exhaust), distinct), inject), (split, split_asm)), nchotomy), case_cong), weak_case_cong) = |
224 (tname, |
224 (tname, |
225 {index = i, |
225 {index = i, |
226 alt_names = alt_names, |
226 alt_names = alt_names, |
227 descr = descr, |
227 descr = descr, |
228 sorts = sorts, |
228 sorts = sorts, |
229 inject = inject, |
229 inject = inject, |
230 distinct = distinct_thm, |
230 distinct = distinct, |
|
231 induct = induct, |
231 inducts = inducts, |
232 inducts = inducts, |
232 exhaust = exhaust_thm, |
233 exhaust = exhaust, |
233 nchotomy = nchotomy, |
234 nchotomy = nchotomy, |
234 rec_names = reccomb_names, |
235 rec_names = rec_names, |
235 rec_rewrites = rec_thms, |
236 rec_rewrites = rec_rewrites, |
236 case_name = case_name, |
237 case_name = case_name, |
237 case_rewrites = case_thms, |
238 case_rewrites = case_rewrites, |
238 case_cong = case_cong, |
239 case_cong = case_cong, |
239 weak_case_cong = weak_case_cong, |
240 weak_case_cong = weak_case_cong, |
240 splits = splits}); |
241 split = split, |
|
242 split_asm = split_asm}); |
241 |
243 |
242 (* case names *) |
244 (* case names *) |
243 |
245 |
244 local |
246 local |
245 |
247 |
318 |
320 |
319 structure DatatypeInterpretation = InterpretationFun |
321 structure DatatypeInterpretation = InterpretationFun |
320 (type T = config * string list val eq: T * T -> bool = eq_snd op =); |
322 (type T = config * string list val eq: T * T -> bool = eq_snd op =); |
321 fun interpretation f = DatatypeInterpretation.interpretation (uncurry f); |
323 fun interpretation f = DatatypeInterpretation.interpretation (uncurry f); |
322 |
324 |
323 fun add_rules simps case_thms rec_thms inject distinct |
325 fun add_rules simps case_rewrites rec_rewrites inject distinct |
324 weak_case_congs cong_att = |
326 weak_case_congs cong_att = |
325 PureThy.add_thmss [((Binding.name "simps", simps), []), |
327 PureThy.add_thmss [((Binding.name "simps", simps), []), |
326 ((Binding.empty, flat case_thms @ |
328 ((Binding.empty, flat case_rewrites @ |
327 flat distinct @ rec_thms), [Simplifier.simp_add]), |
329 flat distinct @ rec_rewrites), [Simplifier.simp_add]), |
328 ((Binding.empty, rec_thms), [Code.add_default_eqn_attribute]), |
330 ((Binding.empty, rec_rewrites), [Code.add_default_eqn_attribute]), |
329 ((Binding.empty, flat inject), [iff_add]), |
331 ((Binding.empty, flat inject), [iff_add]), |
330 ((Binding.empty, map (fn th => th RS notE) (flat distinct)), [Classical.safe_elim NONE]), |
332 ((Binding.empty, map (fn th => th RS notE) (flat distinct)), [Classical.safe_elim NONE]), |
331 ((Binding.empty, weak_case_congs), [cong_att])] |
333 ((Binding.empty, weak_case_congs), [cong_att])] |
332 #> snd; |
334 #> snd; |
333 |
335 |
355 val inducts = Project_Rule.projections (ProofContext.init thy2) induct; |
357 val inducts = Project_Rule.projections (ProofContext.init thy2) induct; |
356 |
358 |
357 val (casedist_thms, thy3) = thy2 |> |
359 val (casedist_thms, thy3) = thy2 |> |
358 DatatypeAbsProofs.prove_casedist_thms config new_type_names [descr] sorts induct |
360 DatatypeAbsProofs.prove_casedist_thms config new_type_names [descr] sorts induct |
359 case_names_exhausts; |
361 case_names_exhausts; |
360 val ((reccomb_names, rec_thms), thy4) = DatatypeAbsProofs.prove_primrec_thms |
362 val ((rec_names, rec_rewrites), thy4) = DatatypeAbsProofs.prove_primrec_thms |
361 config new_type_names [descr] sorts (get_all thy3) inject distinct |
363 config new_type_names [descr] sorts (get_all thy3) inject distinct |
362 (Simplifier.theory_context thy3 dist_ss) induct thy3; |
364 (Simplifier.theory_context thy3 dist_ss) induct thy3; |
363 val ((case_thms, case_names), thy5) = DatatypeAbsProofs.prove_case_thms |
365 val ((case_rewrites, case_names), thy5) = DatatypeAbsProofs.prove_case_thms |
364 config new_type_names [descr] sorts reccomb_names rec_thms thy4; |
366 config new_type_names [descr] sorts rec_names rec_rewrites thy4; |
365 val (split_thms, thy6) = DatatypeAbsProofs.prove_split_thms |
367 val (split_thms, thy6) = DatatypeAbsProofs.prove_split_thms |
366 config new_type_names [descr] sorts inject distinct casedist_thms case_thms thy5; |
368 config new_type_names [descr] sorts inject distinct casedist_thms case_rewrites thy5; |
367 val (nchotomys, thy7) = DatatypeAbsProofs.prove_nchotomys config new_type_names |
369 val (nchotomys, thy7) = DatatypeAbsProofs.prove_nchotomys config new_type_names |
368 [descr] sorts casedist_thms thy6; |
370 [descr] sorts casedist_thms thy6; |
369 val (case_congs, thy8) = DatatypeAbsProofs.prove_case_congs new_type_names |
371 val (case_congs, thy8) = DatatypeAbsProofs.prove_case_congs new_type_names |
370 [descr] sorts nchotomys case_thms thy7; |
372 [descr] sorts nchotomys case_rewrites thy7; |
371 val (weak_case_congs, thy9) = DatatypeAbsProofs.prove_weak_case_congs new_type_names |
373 val (weak_case_congs, thy9) = DatatypeAbsProofs.prove_weak_case_congs new_type_names |
372 [descr] sorts thy8; |
374 [descr] sorts thy8; |
373 |
375 |
374 val simps = flat (distinct @ inject @ case_thms) @ rec_thms; |
376 val simps = flat (distinct @ inject @ case_rewrites) @ rec_rewrites; |
375 val dt_infos = map (make_dt_info alt_names descr sorts (inducts, induct) reccomb_names rec_thms) |
377 val dt_infos = map (make_dt_info alt_names descr sorts induct inducts rec_names rec_rewrites) |
376 ((0 upto length descr - 1) ~~ descr ~~ case_names ~~ case_thms ~~ casedist_thms ~~ |
378 ((0 upto length descr - 1) ~~ descr ~~ case_names ~~ case_rewrites ~~ casedist_thms ~~ |
377 map FewConstrs distinct ~~ inject ~~ split_thms ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
379 map FewConstrs distinct ~~ inject ~~ split_thms ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
378 val dt_names = map fst dt_infos; |
380 val dt_names = map fst dt_infos; |
379 in |
381 in |
380 thy9 |
382 thy9 |
381 |> add_case_tr' case_names |
383 |> add_case_tr' case_names |
382 |> add_rules simps case_thms rec_thms inject distinct weak_case_congs (Simplifier.attrib (op addcongs)) |
384 |> add_rules simps case_rewrites rec_rewrites inject distinct weak_case_congs (Simplifier.attrib (op addcongs)) |
383 |> register dt_infos |
385 |> register dt_infos |
384 |> add_cases_induct dt_infos inducts |
386 |> add_cases_induct dt_infos inducts |
385 |> Sign.parent_path |
387 |> Sign.parent_path |
386 |> store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms) |
388 |> store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms) |
387 |> snd |
389 |> snd |
490 types_syntax constr_syntax case_names_induct; |
492 types_syntax constr_syntax case_names_induct; |
491 val inducts = Project_Rule.projections (ProofContext.init thy2) induct; |
493 val inducts = Project_Rule.projections (ProofContext.init thy2) induct; |
492 |
494 |
493 val (casedist_thms, thy3) = DatatypeAbsProofs.prove_casedist_thms config new_type_names descr |
495 val (casedist_thms, thy3) = DatatypeAbsProofs.prove_casedist_thms config new_type_names descr |
494 sorts induct case_names_exhausts thy2; |
496 sorts induct case_names_exhausts thy2; |
495 val ((reccomb_names, rec_thms), thy4) = DatatypeAbsProofs.prove_primrec_thms |
497 val ((rec_names, rec_rewrites), thy4) = DatatypeAbsProofs.prove_primrec_thms |
496 config new_type_names descr sorts dt_info inject dist_rewrites |
498 config new_type_names descr sorts dt_info inject dist_rewrites |
497 (Simplifier.theory_context thy3 dist_ss) induct thy3; |
499 (Simplifier.theory_context thy3 dist_ss) induct thy3; |
498 val ((case_thms, case_names), thy6) = DatatypeAbsProofs.prove_case_thms |
500 val ((case_rewrites, case_names), thy6) = DatatypeAbsProofs.prove_case_thms |
499 config new_type_names descr sorts reccomb_names rec_thms thy4; |
501 config new_type_names descr sorts rec_names rec_rewrites thy4; |
500 val (split_thms, thy7) = DatatypeAbsProofs.prove_split_thms config new_type_names |
502 val (split_thms, thy7) = DatatypeAbsProofs.prove_split_thms config new_type_names |
501 descr sorts inject dist_rewrites casedist_thms case_thms thy6; |
503 descr sorts inject dist_rewrites casedist_thms case_rewrites thy6; |
502 val (nchotomys, thy8) = DatatypeAbsProofs.prove_nchotomys config new_type_names |
504 val (nchotomys, thy8) = DatatypeAbsProofs.prove_nchotomys config new_type_names |
503 descr sorts casedist_thms thy7; |
505 descr sorts casedist_thms thy7; |
504 val (case_congs, thy9) = DatatypeAbsProofs.prove_case_congs new_type_names |
506 val (case_congs, thy9) = DatatypeAbsProofs.prove_case_congs new_type_names |
505 descr sorts nchotomys case_thms thy8; |
507 descr sorts nchotomys case_rewrites thy8; |
506 val (weak_case_congs, thy10) = DatatypeAbsProofs.prove_weak_case_congs new_type_names |
508 val (weak_case_congs, thy10) = DatatypeAbsProofs.prove_weak_case_congs new_type_names |
507 descr sorts thy9; |
509 descr sorts thy9; |
508 |
510 |
509 val dt_infos = map |
511 val dt_infos = map |
510 (make_dt_info (SOME new_type_names) (flat descr) sorts (inducts, induct) reccomb_names rec_thms) |
512 (make_dt_info (SOME new_type_names) (flat descr) sorts induct inducts rec_names rec_rewrites) |
511 ((0 upto length (hd descr) - 1) ~~ hd descr ~~ case_names ~~ case_thms ~~ |
513 ((0 upto length (hd descr) - 1) ~~ hd descr ~~ case_names ~~ case_rewrites ~~ |
512 casedist_thms ~~ simproc_dists ~~ inject ~~ split_thms ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
514 casedist_thms ~~ simproc_dists ~~ inject ~~ split_thms ~~ nchotomys ~~ case_congs ~~ weak_case_congs); |
513 |
515 |
514 val simps = flat (distinct @ inject @ case_thms) @ rec_thms; |
516 val simps = flat (distinct @ inject @ case_rewrites) @ rec_rewrites; |
515 val dt_names = map fst dt_infos; |
517 val dt_names = map fst dt_infos; |
516 |
518 |
517 val thy12 = |
519 val thy12 = |
518 thy10 |
520 thy10 |
519 |> add_case_tr' case_names |
521 |> add_case_tr' case_names |
520 |> Sign.add_path (space_implode "_" new_type_names) |
522 |> Sign.add_path (space_implode "_" new_type_names) |
521 |> add_rules simps case_thms rec_thms inject distinct |
523 |> add_rules simps case_rewrites rec_rewrites inject distinct |
522 weak_case_congs (Simplifier.attrib (op addcongs)) |
524 weak_case_congs (Simplifier.attrib (op addcongs)) |
523 |> register dt_infos |
525 |> register dt_infos |
524 |> add_cases_induct dt_infos inducts |
526 |> add_cases_induct dt_infos inducts |
525 |> Sign.parent_path |
527 |> Sign.parent_path |
526 |> store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms) |> snd |
528 |> store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms) |> snd |