src/Pure/Isar/expression.ML
changeset 28903 b3fc3a62247a
parent 28902 2019bcc9d8bf
child 28936 f1647bf418f5
equal deleted inserted replaced
28902:2019bcc9d8bf 28903:b3fc3a62247a
   596 end;
   596 end;
   597 
   597 
   598 
   598 
   599 (*** Locale declarations ***)
   599 (*** Locale declarations ***)
   600 
   600 
       
   601 (* axiomsN: name of theorem set with destruct rules for locale predicates,
       
   602      also name suffix of delta predicates and assumptions. *)
       
   603 
       
   604 val axiomsN = "axioms";
       
   605 
   601 local
   606 local
   602 
   607 
   603 (* introN: name of theorems for introduction rules of locale and
   608 (* introN: name of theorems for introduction rules of locale and
   604      delta predicates;
   609      delta predicates *)
   605    axiomsN: name of theorem set with destruct rules for locale predicates,
       
   606      also name suffix of delta predicates. *)
       
   607 
   610 
   608 val introN = "intro";
   611 val introN = "intro";
   609 val axiomsN = "axioms";
       
   610 
   612 
   611 fun atomize_spec thy ts =
   613 fun atomize_spec thy ts =
   612   let
   614   let
   613     val t = Logic.mk_conjunction_balanced ts;
   615     val t = Logic.mk_conjunction_balanced ts;
   614     val body = ObjectLogic.atomize_term thy t;
   616     val body = ObjectLogic.atomize_term thy t;
   693             |> def_pred aname parms defs exts exts';
   695             |> def_pred aname parms defs exts exts';
   694           val (_, thy'') =
   696           val (_, thy'') =
   695             thy'
   697             thy'
   696             |> Sign.add_path aname
   698             |> Sign.add_path aname
   697             |> Sign.no_base_names
   699             |> Sign.no_base_names
   698             |> PureThy.note_thmss Thm.internalK [((Name.binding introN, []), [([intro], [])])]
   700             |> PureThy.note_thmss Thm.internalK
       
   701               [((Name.binding introN, []), [([intro], [NewLocale.unfold_attrib])])]
   699             ||> Sign.restore_naming thy';
   702             ||> Sign.restore_naming thy';
   700           in (SOME statement, SOME intro, axioms, thy'') end;
   703           in (SOME statement, SOME intro, axioms, thy'') end;
   701     val (b_pred, b_intro, b_axioms, thy'''') =
   704     val (b_pred, b_intro, b_axioms, thy'''') =
   702       if null ints then (NONE, NONE, [], thy'')
   705       if null ints then (NONE, NONE, [], thy'')
   703       else
   706       else
   708           val (_, thy'''') =
   711           val (_, thy'''') =
   709             thy'''
   712             thy'''
   710             |> Sign.add_path pname
   713             |> Sign.add_path pname
   711             |> Sign.no_base_names
   714             |> Sign.no_base_names
   712             |> PureThy.note_thmss Thm.internalK
   715             |> PureThy.note_thmss Thm.internalK
   713                  [((Name.binding introN, []), [([intro], [])]),
   716                  [((Name.binding introN, []), [([intro], [NewLocale.intro_attrib])]),
   714                   ((Name.binding axiomsN, []),
   717                   ((Name.binding axiomsN, []),
   715                     [(map (Drule.standard o Element.conclude_witness) axioms, [])])]
   718                     [(map (Drule.standard o Element.conclude_witness) axioms, [])])]
   716             ||> Sign.restore_naming thy''';
   719             ||> Sign.restore_naming thy''';
   717         in (SOME statement, SOME intro, axioms, thy'''') end;
   720         in (SOME statement, SOME intro, axioms, thy'''') end;
   718   in ((a_pred, a_intro, a_axioms), (b_pred, b_intro, b_axioms), thy'''') end;
   721   in ((a_pred, a_intro, a_axioms), (b_pred, b_intro, b_axioms), thy'''') end;
   755     val extraTs = fold Term.add_tfrees exts' [] \\ fold Term.add_tfreesT (map snd parms) [];
   758     val extraTs = fold Term.add_tfrees exts' [] \\ fold Term.add_tfreesT (map snd parms) [];
   756     val _ = if null extraTs then ()
   759     val _ = if null extraTs then ()
   757       else warning ("Additional type variable(s) in locale specification " ^ quote bname);
   760       else warning ("Additional type variable(s) in locale specification " ^ quote bname);
   758 
   761 
   759     val satisfy = Element.satisfy_morphism b_axioms;
   762     val satisfy = Element.satisfy_morphism b_axioms;
       
   763 
   760     val params = fixed @
   764     val params = fixed @
   761       (body_elems |> map_filter (fn Fixes fixes => SOME fixes | _ => NONE) |> flat);
   765       (body_elems |> map_filter (fn Fixes fixes => SOME fixes | _ => NONE) |> flat);
   762     val (body_elems', defns) = fold_map (defines_to_notes thy) body_elems [];
   766     val asm = if is_some b_statement then b_statement else a_statement;
   763 
   767     val (body_elems', defns) = fold_map (defines_to_notes thy') body_elems [];
   764     val notes = body_elems' |>
   768     val notes = body_elems' |>
   765       (fn elems => fold_map assumes_to_notes elems (map Element.conclude_witness a_axioms)) |>
   769       (fn elems => fold_map assumes_to_notes elems (map Element.conclude_witness a_axioms)) |>
   766       fst |> map (Element.morph_ctxt satisfy) |>
   770       fst |> map (Element.morph_ctxt satisfy) |>
   767       map_filter (fn Notes notes => SOME notes | _ => NONE);
   771       map_filter (fn Notes notes => SOME notes | _ => NONE) |>
       
   772       (if is_some asm
       
   773         then cons (Thm.internalK, [((Name.binding (bname ^ "_" ^ axiomsN), []),
       
   774           [([assume (cterm_of thy' (the asm))], [(Attrib.internal o K) NewLocale.witness_attrib])])])
       
   775         else I);
   768 
   776 
   769     val deps' = map (fn (l, morph) => (l, morph $> satisfy)) deps;
   777     val deps' = map (fn (l, morph) => (l, morph $> satisfy)) deps;
   770 
   778 
   771     val loc_ctxt = thy' |>
   779     val loc_ctxt = thy' |>
   772       NewLocale.register_locale name (extraTs, params)
   780       NewLocale.register_locale name (extraTs, params)
   773         (if is_some b_statement then b_statement else a_statement, map prop_of defs) ([], [])
   781         (asm, map prop_of defs) ([], [])
   774         (map (fn n => (n, stamp ())) notes |> rev) (map (fn d => (d, stamp ())) deps' |> rev) |>
   782         (map (fn n => (n, stamp ())) notes |> rev) (map (fn d => (d, stamp ())) deps' |> rev) |>
   775       NewLocale.init name
   783       NewLocale.init name
   776   in (name, loc_ctxt) end;
   784   in (name, loc_ctxt) end;
   777 
   785 
   778 in
   786 in
   801     after_qed raw_target expression thy =
   809     after_qed raw_target expression thy =
   802   let
   810   let
   803     val target = intern thy raw_target;
   811     val target = intern thy raw_target;
   804     val target_ctxt = NewLocale.init target thy;
   812     val target_ctxt = NewLocale.init target thy;
   805 
   813 
   806     val ((propss, deps, export'), goal_ctxt) = prep_expr expression target_ctxt;
   814     val ((propss, deps, export), goal_ctxt) = prep_expr expression target_ctxt;
   807     
   815     
   808     fun store_dep ((name, morph), thms) =
   816     fun store_dep ((name, morph), thms) =
   809       NewLocale.add_dependency target (name, morph $> Element.satisfy_morphism thms $> export');
   817       NewLocale.add_dependency target (name, morph $> Element.satisfy_morphism thms $> export);
   810 
   818 
   811     fun after_qed' results =
   819     fun after_qed' results =
   812       fold store_dep (deps ~~ prep_result propss results) #>
   820       fold store_dep (deps ~~ prep_result propss results) #>
   813       after_qed results;
   821       after_qed results;
   814 
   822 
   825 
   833 
   826 end;
   834 end;
   827 
   835 
   828 
   836 
   829 end;
   837 end;
       
   838