Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Isabelle/HOL/Tools/Ctr_Sugar/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 16.11.2025 mit Größe 52 kB image not shown  

Quelle  ctr_sugar.ML

  Sprache: SML
 


 
    Author
    exhaust_discs

exhaust_selslistjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
*)

CTR_SUGAR
sigregister_ctr_sugar )> >local_theory local_theory
 = Codatatype  

  type ctr_sugar =
    {kind
T:typ
     val: - ' list>java.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85
     :,
     discs: term:term
     selss  val:term-string
     exhaust,
     nchotomy:  :. >string>typ - term >
     :  list
     distincts: thm list,
     case_thms: thm list,
     case_cong: thm
     e(c  ctr_spec  ( *')*alist
     case_distribs: thm
     split: ,
     split_asmval:(c )ctr_spec - c
     disc_defs: thm list,
     disc_thmss: thm list list,
     discIs: thm list,
     disc_eq_cases: thm list,
     sel_defs: thm list,
     sel_thmss: thm list list,
     distinct_discsss: thm list list list,
     exhaust_discs: thm list,
     exhaust_sels: thm list,
     collapses: thm list,
     expandsval args_of_ctr_spec c,)ctr_spec >a
     split_sels: thm list
     split_sel_asms: list
     case_eq_ifs

  val  ctr_options_cmd.context  -bool*bool
  val java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  val ctr_sugar_of: Proof.contextfree_constructors ctr_sugar_kind -
      {:,: .context -> )list >
  val ctr_sugars_of    ctr_options )*(, )  list*  -local_theory
   ctr_sugars_of_global -  list
   ctr_sugar_of_caseProofcontext>  - ctr_sugar java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
 :theory>string-java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
  val ctr_sugar_interpretation: java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
    theory
   :(string>bool >ctr_sugar >local_theory
  val register_ctr_sugar_raw: ctr_sugar
  val register_ctr_sugar: string->bool-  ->  -> 
  val default_register_ctr_sugar_global

  val mk_half_pairss: 'a list * 'list -> ('a * 'a) list list
  val join_halves: int -> 'a list list -> 'list list -> 'a list * 'list list list

  val :typ >term term
  val mk_case: typ list -> typ -> term
  ctrs ,
   name_of_ctrterm >java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
   :  - string
  val dest_ctr list
  val. >    -term
    (split

  type(c, actr_specbindingc) 'java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51

  val disc_of_ctr_spec: ('c, 'a) ctr_spec -> binding
  val ctr_of_ctr_spec: list ,
  val args_of_ctr_spec: ('c, 'a) ctr_spec -> 'a list

  val code_plugin: string

  type   : thm ,
   ctr_options_cmd Proofcontext >string>) 

   thm
     : list
list:Proof.context>tactic list >
    ( *)*(termbindingctr_spec) *term - local_theory>
    ctr_sugar  (kind,ctrs, ,selss,nchotomy, distincts
  val    ,case_congcase_cong_weakcase_distribssplitsplit_asm disc_defs ,
    ((. >Plugin_Name) *bool binding
collapses,,,case_eq_ifs}:ctr_sugar =
    kindkind
  :ctr_options
 : 
  val   . phi,
valparse_ctr_options java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
   :'  >aparser - (c a)parser
  val parse_sel_default_eqs: string map. phidistincts
end;

 Morphismphi,
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6

 Ctr_Sugar_Util
open
open map Morphism phi)),

datatype ctr_sugar_kind = disc_eq_cases  (.thm)disc_eq_cases,

type ctr_sugar   map(. ) ,
  {: ,
   T: typ,
   ctrs: term list,
   casex: term  map. phi ,
   discs  )expands
   selss:split_sels,
     map. phi,
   nchotomy:=(.thm)case_eq_ifs
   injects:
   :thm,
   case_thms: thm list,
   case_cong: thm,
   case_cong_weak: thm,
   case_distribs: thm list,
   : thm
   
   disc_defs thm,
        .empty
   :  list
   
   sel_defsctr_sugar_of_gener 
     .( Contexttheory_of )  #)oSymtablookupData context)
   distinct_discsss: java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   exhaust_discs:  list
   exhaust_sels: thm list,
   collapses: thm list,
   expands: functr_sugar_of_case_generic context s ==
   :thmjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
   split_sel_asms: thm list,
java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 26

fun morph_ctr_sugar ctr_sugars_of_global=ctr_sugars_of_generic.;
    case_thms = ctr_sugar_of_case_genericoContextProof
    discIs , sel_defs, sel_thmss, distinct_discsssexhaust_discs ,
    structure = (typeT =ctr_sugar;
  { ctr_sugar_interpretation name =
   T = Morphism  Ctr_Sugar_Plugininterpretation  (fnctr_sugar >fnlthy>
      (.term)ctrs,
   casex = Morphism
      (Morphismterm)discs,
   selss = mapregister_ctr_sugar_raw    name,) ..} java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
   exhaust . phiexhaust
   nchotomy = Morphism.thmin. Symtabnameposmorph_ctr_sugar ctr_sugar)contextend;
   injectsregister_ctr_sugarplugins 
   distincts = map (Morphism.thm phi) distincts,
   case_thms = map (Morphism.thm phi) case_thms,
   case_cong  Morphism  case_cong
   case_cong_weak = 
   case_distribs =map )case_distribs
split  . phisplit
         =Dataget ContextTheorythy);
   disc_defs    valpos = Position.thread_data (;
   disc_thmss = map (mapin
   discIs
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
          . .dataplugins)
   sel_thmss ;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  (orphism) exhaust_discs
   exhaust_selsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   collapses
   expands = "case_cong;
 collapseN ="
   discN =""
    =  Morphism.)case_eq_ifs

   ;

structure  "
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  ="
  val""
selN "sel;
)  exhaust_sel

fun  
  Option split_asm

fun ctr_sugars_of_generic java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
  Symtab case_distrib

fun  cong_attrs{attributes cong
   dest_attrs@attributes [est}
val safe_elim_attrs { [elim}

val valiff_attrs  @attributes
val ctr_sugar_of_global = ctr_sugar_of_genericjava.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53

val ' (: xs,  :)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
val    Context

val ctr_sugar_of_case =
val  =ctr_sugar_of_case_generic.;

structurejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

fun ctr_sugar_interpretation Library  ))
Ctr_Sugar_Plugin  fn  = fn =
    f (transfer_ctr_sugar (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

val interpret_ctr_sugar = Ctr_Sugar_Plugin.data;

fun register_ctr_sugar_raw     Ts0  )t
  Local_Theory   t
    ( phi >fn =
      subst_nonatomic_typesbodyT:Ts0Ts)
      in

fun register_ctr_sugar
  casehead_ofof

fun default_register_ctr_sugar_global plugins (Long_Name prefix) 'java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
<Boundclose>t'><>=java.lang.StringIndexOutOfBoundsException: Index 115 out of bounds for length 115
    val tab t= name_of_const"(perhaps( domain_type) t)
    val pos = Position.thread_data ();
  in
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
      thy
>. (.put(.update_newname pos ctr_sugar)tab
      |> Named_Target.theory_map (Ctr_Sugar_Plugincase find_first fo_match  f)ctrsof
  end;

val        NONE=  Fail"")
val = "java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
val not_prefix = "( Term.strip_comb t of

fun     casectr_sugar_of  s 
  | mk_unN _ l suf = un_prefixSOMEctr_sugar {  Const case_name )  =discs0,selss  selss0, .})=

val caseN = "case";
valcase_congN case_cong";
val case_eq_ifN = "case_eq_if";
val collapseN = "collapse";
val discN = "disc";
val disc_eq_caseN = "disc_eq_case";
valdiscIN="";
val distinctN = "distinct";
val distinct_discN =            let
val =exhaust;
val exhaust_discN = "exhaust_disc";
   expand
val injectN = "inject";
   nchotomy;
val selN = "sel";
 exhaust_selN ""
val splitN = "split";
  split_asm
val split_selN =val'  curryTerm.betapplys)branches;
val split_sel_asmN = " (ctr_sugar,conds ')
val splitsN           
val split_selsN
val case_cong_weak_thmsN
val case_distribN = )

val cong_attrs = @{attributes [cong]};
val dest_attrs
val  = @attributes [!]};
val iff_attrs = @{attributes [iff]}|const_or_free_nameFree (s, _)  s
val inductsimp_attrs [induct_simp];
val nitpicksimp_attrs 
val simp_attrs extract_sel_default ctxt t =

fun eq  =( '=  eq 'ys;

fun'_ [, [)= [
  
     (sel ctrvars)) ) =

fun mk_half_pairss p        (Term.replace_dummy_patterns(Syntax.heck_term t))

fun join_halves nhalf_xssother_half_xss
  (splice (flat      |>>(Term.dest_comb
   map2 (map2 .strip_comb#>dest_Const_name
     (      handleTERM_ >  )

 mk_undefined T = Const \^>\open>\close>,T;

fun
       (
    end
  end;

fun mk_case Ts T t =
let( Ts0)= fastype_of > . in
.allow_dummies
  ;

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  (,_ disc

valargs_of_ctr_specargs ;

fun name_of_disc code_plugin . \binding\open>code<>java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
  
plugins prep_plugins raw_plugins
    Long_Name
  |  _ ,\^Const_\openHOL   \open \<lose>t\> =
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  |     ;
    Long_Name
   '  ""(trydomain_type )java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72

val base_name_of_ctr = Long_Name.base_name o name_of_ctr;

fun dest_ctr ctxt s
 valf args  .strip_combtin
    (case ctr_sugar_of
      SOME {,. >
      (case find_first (body_type(fastype_of hd))java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48

      | NONE   forall((  (, )=  =fcT_name| _= )obody_type not  type;
|NONE>raise  "dest_ctr
  end;

fun dest_case
  (case Term.strip_comb t of
          mandatory  Binding.qualifymandatory fc_b_name
    (case ctr_sugar_of     (, B =
>variant_tfreesmap  dest_TFree_or_TVar)
if   
        letjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
          if n < length args then
            let
              val    val  = map (  ) ctrs
              val  k
val mapmap);
              val conds can_rely_on_disc
                 (fn = map obj  @leftoversselss
                  1 n=2andalso (3 )java.lang.StringIndexOutOfBoundsException: Index 91 out of bounds for length 91
            in
              SOME
java.lang.StringIndexOutOfBoundsException: Range [39, 15) out of bounds for length 15
          else
            NONE
        end
      else
        NONE
    | _ => NONE)
_ =NONE

fun const_or_free_name (else Binding, )then
  const_or_free_name ,) s
  |java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15

fun extract_sel_default ctxt
java.lang.StringIndexOutOfBoundsException: Range [21, 5) out of bounds for length 5
    fun malformed () =
                ifBinding   Binding. sel

              
fst. Syntax ctxtt0
      |> HOLogic.dest_eq
      >Term
              . distinctop= filterjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
        #>Term #>> dest_Const_name
      handle TERM     ((((u, ) xss, ),fsgs) ) p '))_ =no_defs_lthy
  in
    if forall (is_Free orf is_Var) vars andalso not (has_duplicates (op aconv) vars) then
      ((ctr, sel|> mk_Freess""ctr_Tss
    else
      malformed>mk_Frees 
  

(* Ideally, we would enrich the context with constants rather than free variables. *)mk_FreesPHOLogic;
_for_sel_defaultsjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
.
  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  #

type ('c, 'a) ctr_spec = (nicer names

fun eta_gsmap2fold_rev. xgs
fun ctr_of_ctr_speccase_binding 
fun  (args)= ;

  =Plugin_Name \^binding\<>code<close>

fun prepare_free_constructors kind prep_plugins Bindingeq_name(raw_case_binding, standard_binding 
    (((java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
  java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
insprep_pluginsno_defs_lthyjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56

    

     raw_ctrs  ctr_of_ctr_specctr_specs
    val raw_disc_bindings>snd Local_Theorybegin_nestedjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
args_of_ctr_spec;

    val  =length raw_ctrs
val=  ;

         =. phi

    casexBool  . ;

      )=HOLogic (, ;
      (case
         T '
      | _ => error "Expected type constructor in body type of constructor");
     _  ( Type(, )= fcT_name  false) body_type
 )(l) "   same type"java.lang.StringIndexOutOfBoundsException: Index 86 out of bounds for length 86

name= fcT_name
    val (let  b  nth disc_bindings  1 java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49

    fun qualify mandatory =         );

    val (unsorted_As, [      ( Bindingis_empty)raw_disc_bindings :raw_sel_bindingss
      no_defs_lthy     all_sels_distinctdiscs,selssdisc_defs,sel_defss,lthy) java.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81
      |> variant_tfrees
      ||> fst o mk_TFrees 2;

    val As  all_sel_bindingsflatsel_bindingssjava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52

     fcT  fcT_nameAs
    val ctrs = map (mk_ctr As) uniq_sel_bindings )
    val java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33

    valms=map ;

    fun can_definitely_rely_on_disc k =
notBinding.is_emptynth  ( -))orelse  (k- 1 0java.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87
    can_rely_on_disc
      can_definitely_rely_on_disc k orelseval 
    funshould_omit_disc_binding  =   orelse (-k);

    val equal_binding = \<^binding>\<open>=\<close>;

    fun is_disc_binding_valid b =
not(.is_empty b  Bindingeq_name(equal_binding)

    val standard_disc_binding =          val sel_bindings=mapfst;

                  sel_default_eqs then
      raw_disc_bindings
      |> @{map 4} (fn k => fn m => fn ctr]
        qualify false
          (                sel_Ts ( op>    osndsndo  o)sel_infos
             if m = 0 then equal_binding
             else if should_omit_disc_binding k then               ;
             else standard_disc_binding
else . disc standard_binding)then
             standard_disc_binding ctr
           else
             ))  msctrs0

    fun

    val sel_bindingss =
      @map }( ctr => fn =  (fn =fn >
        java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
( .is_empty sel  Binding. (, standard_binding) then
            standard_sel_binding              (case .lookup (op =proto_selskof
          else
            ) 1  mo pad_listBinding )ctrs0  raw_sel_bindingss

    val add_bindings]>fold_revTerm    Nameuu Tsmk_undefined)
      . distinct.java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
        (map Binding.name_of|SOMExs  >fold_revTermlambdaxsx ctrs ;
      #>

    let

    val ((( )xss)fs gs,w), p ') _) 
      |> add_bindings op ( fstproto_sels java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
 ( )fcT
      ||]= )
      ||>> mk_Freess "x" ctr_Tss
      ||>> mk_Freess "y" ctr_TssvalT
      ||>> mk_Frees "f" case_Ts
      ||>> mk_Frees "g" case_Ts
      ||>> yield_singleton
      ||> yield_singleton( ( ~)oo'"" HOLogic.boolT;

    val                     quoteSyntax. lthy))

       map2 (curryTerm)ctrs;
    val yctrs = map2 (curryTermlist_combmk_case  T case0, mk_sel_case_args  proto_sels )$u)

    valjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
valxgs  Term)gs;

    (* TODO: Eta-expension is for compatibility with the old datatype package (but it also provides|  Local_Theorybegin_nested
       nicer names). Consider removing. *)

    val eta_fs = map2 (fold_rev Term.lambda) xss xfs;
  = fold_rev.lambda)xss;

    val case_binding =
      qualify false
        if .is_empty orelse
            Binding.eq_name (raw_case_binding, pair.lambda exist_xs_u_eq_ctrjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
Binding caseN_
         else
           ksexist_xs_u_eq_ctrs

    fun mk_case_disj xctr xf xs =
list_exists_free (. HOLogicmk_eq(, xctr. wxf)java.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93

    val case_rhs = fold_rev (fold_rev Term.lambda) [fs, [u]]
      (Const            |> .end_nested
Termw(.foldr1 .mk_disj@{mapmk_case_disj  xss)

    val  mapMorphism raw_disc_defs
|(  .begin_nested
      |> Local_Theory.define val =unflat_selss;
Binding . case_binding[),case_rhs
      ||> `Local_Theory.end_nested    mapterm)raw_sels)

    val phi = Proof_Context.export_morphism lthy_old lthy;

    val    map ) selss0

    val case0 all_sels_distinct,,disc_defs sel_defs, sel_defss'
    val casexfun Logic QsHOLogicmk_Trueprop;
    val val 
         HOLogicboolT case0

    funmk_uu_eq)= HOLogic ,u;

    val exist_xs_u_eq_ctrs =
      map2 (let

    val unique_disc_no_def =          mk_goal yctr xsys 
    val alternate_disc_no_def=FalseE;(arbitrary*)

    fun alternate_disc_lhsHOLogicmk_conj( ( HOLogicmk_eqxs ys));
      HOLogic.mk_not
        (let val b = nth disc_bindings (k - 1in
            is_disc_binding_validbthen  b( -1) nthexist_xs_u_eq_ctrs( -1)
         end);

    val no_discs_sels =
      not discs_sels
      forall ( Binding.is_empty (raw_disc_bindings :raw_sel_bindingss
      null sel_default_eqs;

    funmk_goal(xs,xc),,(',xc') ==
      if no_discs_sels then
        (true, [], [], [], [], [], lthy)
      else
        let
          val all_sel_bindings=flatsel_bindingss
                      HOLogic.k_Trueprop (.mk_not (.mk_eq(xc xc)));
          val uniq_sel_bindings = distinct Binding.eq_name all_sel_bindings;
          val all_sels_distinct = (length uniq_sel_bindings = num_all_sel_bindings

          val
            if all_sels_distinct then
              1 upto num_all_sel_bindingsval goalss = [exhaust_goal] :inject_goalss@half_distinct_goalss;
            else
              map (fn

          val| java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
          val sel_infos =
            AList.group (op =) (sel_binding_index ~~ all_proto_sels)
            |> sort (int_ord o apply2 fst)
            |> map snd|>curry(op ~~) uniq_sel_bindings;
          val sel_bindings = map fst sel_infos;

          val sel_defaults =
            if null sel_default_eqs then|>yield_singleton( h" B --> C)
              ]
            |>yield_singleton (mk_Frees "" HOLogic.boolT
              
                valxfs = curry.list_comb fsxssjava.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
val 
                  fake_local_theory_for_sel_defaults (sel_bindings
              in
                map ((xtract_sel_default o  fake_lthy) sel_default_eqs
              end;

          fun disc_free b = Free (Binding.name_of b, mk_pred1T fcT);

          fun disc_spec

          fun alternate_disc k =
sc_lhs(Ko  rapp u  disc_free ( -k);

          fun mk_sel_case_args b proto_sels T =
            @{map 3} (fn 
(caseAListlookup op)proto_sels kjava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
                NONEjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                (case filter (curry (op
                  [] => fold_rev java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                | [(_, t)] => t
                 _>error"Multiple default  constructorpair)
              | SOME (xs, x) => fold_rev Term.lambda xs x)) ctrs ctr_Tss ks;

          fun sel_spec b proto_sels =
            let
              val _ =
                (caseduplicates ) ( fst proto_sels of
                   k 
                     "   "  quote (.string_of_term  (nthctrs  1))
()
              val T =
                (case(. rho_As .empty)(.zero_var_indexes thm))java.lang.StringIndexOutOfBoundsException: Index 91 out of bounds for length 91
                  [T] => T
                | T :: T' :: _ => error ("Inconsistent range java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                    quote (Binding.name_of b) ^ ": " ^
                    " vs. " ^ quote (Syntax.string_of_typ lthy T')));
            in
         nchotomy_thm
                Termjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
            ;

          fun unflat_selssLibrary.foldr1exist_xs_u_eq_ctrs)java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68

          val (((raw_discs, raw_disc_defs), (raw_sels, raw_sel_defs)), (lthy', lthy)) =
            lthy
            > ( o Local_Theory.begin_nested)
            |> apfst split_list o @{fold_map 3| Thmclose_derivation\<here
                ifBindingis_emptyb then
                  if n = 1 then pair (Term.lambda u (mk_uu_eq ()), unique_disc_no_def)
                  else pair(alternate_disc k,alternate_disc_no_def)
                else if Binding.eq_name (b, equal_binding) then
                   (.lambdau exist_xs_u_eq_ctr)
else
                  Specification.definition (SOME (b, NONE, NoSyn)) [] []
                    ((Thm.def_binding b,             @{map 4} (n k>fn goal => fn injects => fn distinctss =>
              ks exist_xs_u_eq_ctrs                 .prove_sorry lthy[ [ goal (fn{ = txt, .}=>
            ||>  split_list  fold_map(fn(,proto_sels =>
              Specification.definition (SOME                |>Thmclose_derivation\^>)
                (.def_binding bb,[]) sel_spec b ) #> apsnd snd) sel_infos
            ||>            mk_prem xsxf xg=

          val phi =               fold_revLogic xs. mk_Trueprop_eqv, xctr,

          val disc_defs = map             goal=
          val              .list_implies (v_eq: { 4}mk_prem xctrsxss xgs,
          val sel_defss = unflat_selss sel_defs;

          val =Variableadd_free_nameslthy goal[
val   ( Morphism )raw_selsjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71

          val discs = mapmk_case_cong_tac ctxt ),
          val  =mapmapmk_disc_or_sel As) selss0
        in
          (all_sels_distinct, discs,            > apply2Thm <here>)
        end

    java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

    val exhaust_goal  xctrxsf_xs java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
      let fun mk_prem xctr xs             HOLogic.mk_not (q$f_xs));
        fold_rev Logic.all [p, exh_y] (mk_imp_p (map2
      ;

    val  
      let@map } mk_split_conjunctxctrs xss ));
        fun mk_split_asm_goalxctrs xss =
                     (plit_lhs,HOLogicmk_not(.foldr1 .
            fold_rev. (s  ) ( (HOLogic.mk_eq (xctr yctr,
              Library.foldr1 HOLogic.mk_conj (map2 (
      java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
        >  >.  =,prems >
      ;

    val half_distinct_goalss =
      let
        fun          . lthy
          fold_rev.all(xs ')
            mk_split_asm_tac ))
      in
        map (map mk_goal) (mk_half_pairss (`I (xss ~~ xctrs)))
      end

    val goalss =              = xctrsxss;

    fun 
      let
        val ((((((((u, val prove_split_asm ;
          
          |> yield_singleton (apfst (op;
 sel_defssel_thmssnontriv_disc_defs,,
              ,distinct_disc_thms,
          ||>> mk_Frees "g" case_Ts
          ||>> yield_singleton (if java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
          else
           uselss mapu);

        val xfs = map2 (curry Term.list_comb) fs xssvalusel_fs =map2curry. ;
        val xgs = map2 (curry Term.list_comb) gs xss;

        val fcase = Term.list_comb (casex, fs);
funmake_sel_thm   
        val ufcase = fcase $                
 fcase$vjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31

        val 
        val eta_gcase = Term.list_comb (casex, eta_gs);

        val eta_ufcase = eta_fcase $ u;
        val eta_vgcase = val = { }(ap make_sel_thm'case_thms;

        fun mk_uu_eq () = HOLogic.mk_eq(  (HOLogic.dest_eq HOLogicdest_TruepropThm thm)of

        val uv_eq = mk_Trueprop_eq

        val ((inject_thms

        val rho_As =
           fn=  ') > 's sel_defs
global )

        fun inst_thm t thm =
                         mk_unique_disc_def)
            (val =the_singlejava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40



          = base_name_of_ctrctrs

          = map fnthm RSnot_sym))half_distinct_thmss

valdistinct_thms,(istinct_thmsss,distinct_thmsss java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
           half_distinct_thmss | transposejava.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85

        nth k-1)
          let
            val goal =
. HOLogicmk_all fst u' '
                Library.foldr1 HOLogic.mk_disj exist_xs_u_eq_ctrs));
          in
            .   ]goal(fncontext  ctxt, prems>
mk_nchotomy_tacn exhaust_thm
            |> Thm
          end;

valcase_thms =
          let
            val goals =
              @{map 3} (fn java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                 Logic.allfs )( ( $, xf)   xss
          in
            @{map 4} . (,unique_disc_no_def  java.lang.StringIndexOutOfBoundsException: Index 89 out of bounds for length 89
                Goal.prove_sorry
                    n case_def distinctss
                |> Thm.close_derivation \<^herediscI_thms
              ks goals inject_thmss distinct_thmsss
          end

        val ( not_discI_thms
          let
                    lthythms}defRS@ [ _  Not)
              fold_rev Logic.all
                mk_Trueprop_eq (xflet

            val|mk_thm _not_discI distinct   RSnot_discI;
              . ( ::@map }mk_prem xctrs xfs,
                 mk_Trueprop_eq (eta_ufcase                
            val weak_goal = Logicmap2  >if b  Ielse ]disc_bindings
            val vars = Variable.add_free_names lthy goal [];
            val weak_vars = Variable.add_free_names lthy weak_goal [];
          in
            (Goal.prove_sorry lthy vars [  java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
               mk_case_cong_tac ctxt uexhaust_thm case_thms
             Goal.prove_sorryjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
               etac ctxt arg_cong|mk_goal(_ ), (_,udisc) 
            |> apply2 (Thm[.allu(.mk_implies HOLogicmk_Trueprop,
endjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14

        val.  [ ] { =ctxtprems_ =  ctxt

         mk_split_conjunctxctr f_xs
          list_all_freejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        fun mk_split_disjunct xctr xs f_xs =
           xs HOLogic.mk_conjHOLogic u,xctr
            HOLogic.mk_not (q $ half_thmss

        fun mk_split_goal xctrs xss xfs =
          mk_Trueprop_eq mk_half_distinct_disc_tac ctxtm disc_thm
            mapmk_split_conjunctxss)
        fun mk_split_asm_goal xctrs
          mk_Trueprop_eq (split_lhs, HOLogic.mk_not (Library.foldr1 HOLogic.mk_disj
            (@{map 3} mk_split_disjunctmap2map2fn thm=  fn  =>

        other_half_goalss
          Variablejava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
          |> (fn vars =>end;
            mk_split_tac  java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
>

        fun
Variable  asm_goal]
          |mk_exhaust_disc_tac  discI_thms
hm)
                ;

         split_thmsplit_asm_thm)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
          let
            val goal val=. udisc;
              =mk_split_asm_goal  xssxfs

val prove_splitreplicate  ]goal
            val asm_thm = prove_split_asm asm_goal thm;
          in
            thm, asm_thm)
          end;

        val (sel_defs, all_sel_thms, sel_thmss, nontriv_disc_defs, disc_thmss, nontriv_disc_thmss,
             discI_thms, nontriv_discI_thms, distinct_disc_thms, distinct_disc_thmsss,
             ,exhaust_sel_thmsall_collapse_thms,
             expand_thms, split_sel_thmsmk_collapse_tac m  sel_thms   ( ))
          ifno_discs_sels
            (], ,] ] ] ] ] ][,] [,[ ],] [, [, ] ,]
          else
            let
              val udiscs = map (rapp(fn    |falsethm  )trivs thmsjava.lang.StringIndexOutOfBoundsException: Index 96 out of bounds for length 96
              val uselss       then    sym ;
              val usel_ctrs = map2fun    mk_Trueprop_equsel_ctr]
              val usel_fs = map2 (curry Term.list_comb) fs uselss;

              val vdiscs = map                  valgoal=fold_rev Logicall  (mk_imp_p map usel_ctrs;
              valvselss   map rapp) ;

              fun make_sel_thm xs' case_thm sel_def =
                zero_var_indexes
                  (Variable.gen_all
                    (Drule
                      (map (SOME o fst) xs')                    ifk   then [ else [ (udisc vdisc))@
                      (Thm.forall_intr_vars (case_thm RS (sel_def RS trans)))));

              val sel_thmss = @{map 3} (map oo make_sel_thm) xss' case_thms sel_defss;

              fun has_undefined_rhs thm =
                (case snd (HOLogic.Library Logic
Const\const_name<>\close >true
                | _ => false);

              val all_sel_thms =
                (if all_sels_distinct andalsovaluncollapse_thms
                    sel_thmss
                 
                   map_product (fn s => fn                in
                     (xss ~case_thms)
ilter_out;

               mk_unique_disc_def ( 
                let
                  valm =the_single
                  val goal = mk_Trueprop_eq (mk_uu_eq;
                  val vars = Variable
                
                  Goal.prove_sorry                     mk_split_asm_goalusel_fs
                    mk_unique_disc_def_tac ctxt m uexhaust_thm)val  prove_split_asm ;
| . \^here
                end;

               mk_alternate_disc_def=
                let
                  val goal =
java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
                       exist_xs_u_eq_ctrs  );
                  val vars = Variable.add_free_names lthy                   .prove_sorrylthy [goalfn{= ,.. >
                Thm>
                  
                    mk_alternate_disc_def_tac ctxt                 
                       2  k))
                  |> Thm.close_derivation \<^here>
java.lang.StringIndexOutOfBoundsException: Range [62, 20) out of bounds for length 20

              val has_alternate_disc_def =
                exists (fn def

                    fncontext java.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95
>.close_derivation<^herejava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
                  refl]);

              val disc_defs' =
                map2 (fn k => fn def =>(sel_defs, all_sel_thms sel_thmss , disc_thmss ,
                   eq_thm_prop(, unique_disc_no_def)  (
                  else if Thm[exhaust_disc_thm],[exhaust_sel_thm,all_collapse_thms,safe_collapse_thms
                   )ksdisc_defs;

              val discD_thms = map (fn def => def RS iffD1) end
               discI_thms =
                map2 (java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
disc_defs
              val not_discI_thms h   ( args
                map2 (fn m    mk_Trueprop_eq $ufcase (,args  u;
                     lthy@thms} def thm[  Notjava.lang.StringIndexOutOfBoundsException: Index 89 out of bounds for length 89
                  ms disc_defs';

               disc_thmssdisc_thmss java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
                let
fun discI ]reflRS
                    | mk_thm _ not_discI [distinct] = distinct RS not_discI;
  discInot_discIdistinctss  mapmk_thm discI not_discI
                in
                  val =
                end;

              val nontriv_disc_thmss =
                map2 (fn b =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

              (flatnontriv_disc_eq_thmss)
(n=1andalsoBinding. b orelseBinding.eq_name(bequal_binding

              val nontriv_discI_thms =
                flat (map2 ( case_cong_thm],)
                  discI_thms);

              val (distinct_disc_thmscollapseNsafe_collapse_thms  =0  ]else )
                
                  fun mk_goal [] = []
                    | mk_goal [((_,   @inductsimp_attrs)
                      [Logic.all u (Logic.mk_implies (HOLogic           exhaustN exhaust_thm [, ])
HOLogic HOLogicmk_not udisc)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72

                  fun tac  =
ext, _ >  ctxtjava.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 97
                    |> Thm.close_derivation \<split_selN,plit_sel_thms

                  split_selsN  @,[]

                  val half_goalss = map mk_goal|  ( o#)
                  val half_thmss =
                    @{map 3} (fn [] ,])]);
                        fn disc_thm =>
  mk_half_distinct_disc_tac  discDdisc_thm)goal])
                      half_goalss half_pairss (flat disc_thmss');

                  val other_half_goalss = map (mk_goal o map swap) half_pairss;
                   other_half_thmss=
                    map2 (map2 (            AListgroup (eq_list(op ))( ((singleo lhs_head_of all_sel_thms)
                        mk_other_half_distinct_disc_tac ctxt thm))) half_thmss
                      ;
                in
                  join_halvesnhalf_thmssother_half_thmss|> transpose
                  |fn = .register


              val exhaust_disc_thm =
let
                  fun mk_prem udisc = mk_imp_p [HOLogic.mk_Trueprop udisc];
                  goal  Logicallp ](mk_imp_p (mapmk_prem udiscs));
                in
Goal.prove_sorry lthy] [  (fn{context =ctxtprems =_ =>
                    mk_exhaust_disc_tac ctxt nMorphism phi)As
                   .close_derivation \<^here>
                end;

              valI))
                let
                  fun mk_goal m udisc usel_ctr          * fordatatype_realizer.ML:java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
                    let
                      val prem =HOLogicmk_Truepropudisc
                      val            exhaust exhaust_thmnchotomy =nchotomy_thminjects  inject_thms
                    case_cong_weak,case_distribs[case_distrib_thmjava.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
                      (            , =discI_thmsdisc_eq_cases,
                    end;
                  val (trivs, goals  ,expands expand_thms   split_sel_thms
                    java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
                    @{map 5      
                        Goal.prove_sorry lthy []end;
                          goalssafter_qed )
                        |> Thm.close_derivation \<^here>
                        |> not triv ? perhaps (try (fn thm => refl RS thm)))
                      ms discD_thms sel_thmss trivs goals;
                in
                  (map_filter (fn (true, _) => NONE  . hereoo. lthy)  tacss
                   thms
                end;

                =
                map2 (fn m => fn thm =>Prooftheorem NONE (sndoo after_qed map( rpair [) goalss) lthy) oo

              java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                let
                  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
val = fold_revLogicallp ](mk_imp_p (ap mk_prem usel_ctrs))java.lang.StringIndexOutOfBoundsException: Index 90 out of bounds for length 90
                in
                  Goal.prove_sorry lthy [] [valdefault_ctr_options:ctr_options= Plugin_Namedefault_filter, );
                    mk_exhaust_sel_tac  swapped_all_collapse_thms
                  |> Thm.close_derivation
                end;

              val expand_thm =
                let
                    k udiscusels  vsels
(  =n thenelse[mk_Trueprop_eq (udisc, vdisc)]) @
                    (if null usels then
[]
                     else
                       [Logic.list_implies
                          (if n = 1 then [] else map HOLogicdefault_ctr_options_cmd
                             HOLogic.mk_Trueprop (Library.foldr1 HOLogic.  parse_opt_binding_colon--parse_ctr-- Scan parse_arg
                               (al parse_ctr_specs  .enum1 | parse_ctr_spec .term .binding;

                  val goal =
                    Library.foldr
                      { 5mk_premsudiscs  vdiscsvselssuv_eq)
                   =
 
                .dd_free_names goal[
                in
                  Goal.prove_sorry lthy vars [
                    mk_expand_tac ctxt n 
                      (inst_thm v exhaust_disc_thm
                      distinct_disc_thmsss')
                   antiquote_setup  
                end;

              val (split_sel_thm, split_sel_asm_thm) =
                let
                  val(n ctxt>fn (os)>
                  val goal =fun  ()=
val  usel_ctrs ;

                        
                   asm_thmprove_split_asm ;
                in
                  (thm, asm_thm)
                end;

              val case_eq_if_thm =
                let
                  val goal = =  Logic ;
                  val vars = Variable.(. pretty_priority 1001ctxt);
                in
                  Goal.prove_sorry lthy vars [] goal (fn {context = ctxt, ...map binder_typesfastype_of ctr));
mk_case_eq_if_tac ctxt uexhaust_thmcase_thmsdisc_thmss'sel_thmss
                  |> Thm.close_derivation \<^here>
                ;

              val disc_eq_case_thms =
                let
                  fun const_of_bool b = if b then \<^Const>\<open>True\<close> else \<^Const>\<open>False\<closeend;
                  fun  
                    
                  val goals = map_index (fn (n, udisc) =>
                    mk_Trueprop_eq (udisc, list_comb(ntiquote_setup\<binding\openclose false#
                   goal=Logic goalsjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65

                in
(
                    
                       exhaust_thm (flat nontriv_disc_thmss) distinct_thms case_thms)
                  Thmclose_derivation ^>
                  |> Conjunction.elim_balanced (length goals)     Export_Theoryexport_enabled 
                end;
            in
              (sel_defs, all_sel_thms, sel_thmss, nontriv_disc_defs, disc_thmss,         val  =
               discI_thms nontriv_discI_thms, distinct_disc_thms, distinct_disc_thmsss
               [exhaust_disc_thm], [exhaust_sel_thm], all_collapse_thms, safe_collapse_thms,
               [xpand_thm], split_sel_thm], split_sel_asm_thm],[ase_eq_if_thm]java.lang.StringIndexOutOfBoundsException: Index 84 out of bounds for length 84
               )
            end;

        val case_distrib_thm =
          let
                               typ LogicunvarifyT_globalT
               valargs)=mk_Frees   lthy
                fold_rev    ( .add_tfrees (ogicmk_typetyp:: ) [)
              )fs ;
            val goal = mk_Trueprop_eq (h $ ufcase                in
            valvars  .add_free_nameslthy goal]
          in
            Goal.prove_sorry lthy vars [] goal (fn {
              mk_case_distrib_tac  (Thmcterm_of ctxt )exhaust_thmcase_thms
            |>        
          end          .export_bodydatatypes

        val exhaust_case_names_attr = list(pair  pair  ( pair )
s_type_attr.internal<^> K(.cases_typefcT_name)

        val nontriv_disc_eq_thmss =
          map (map (else)
            handle THM _ => ;

        val anonymous_notes =
          [(map (fn th => th RS notE) distinct_thms, safe_elim_attrs),
           (flat nontriv_disc_eq_thmss, nitpicksimp_attrs)]
          |> map (fn (thms, attrs) => ((Binding.empty, attrs), [(thms, [])]));

        val notes =
          [(caseN, case_thms, nitpicksimp_attrs @ simp_attrs),
           (case_congN, [case_cong_thm], []),
           (case_cong_weak_thmsN, [case_cong_weak_thm], cong_attrs),
           (case_distribN, [case_distrib_thm], []),
           (case_eq_ifN, case_eq_if_thms, []),
           (collapseN, safe_collapse_thms, if ms = [0then [] else simp_attrs),
           (discN, flat nontriv_disc_thmss, simp_attrs),
           (disc_eq_caseN, disc_eq_case_thms, []),
           (discIN, nontriv_discI_thms, []),
           (distinctN, distinct_thms, simp_attrs @ inductsimp_attrs),
           (distinct_discN, distinct_disc_thms, dest_attrs),
           (exhaustN, [exhaust_thm], [exhaust_case_names_attr, cases_type_attr]),
           (exhaust_discN, exhaust_disc_thms, [exhaust_case_names_attr]),
           (exhaust_selN, exhaust_sel_thms, [exhaust_case_names_attr]),
           (expandN, expand_thms, []),
           (injectN, inject_thms, iff_attrs @ inductsimp_attrs),
           (nchotomyN, [nchotomy_thm], []),
           (selN, all_sel_thms, nitpicksimp_attrs @ simp_attrs),
           (splitN, [split_thm], []),
           (split_asmN, [split_asm_thm], []),
           (split_selN, split_sel_thms, []),
           (split_sel_asmN, split_sel_asm_thms, []),
           (split_selsN, split_sel_thms @ split_sel_asm_thms, []),
           (splitsN, [split_thm, split_asm_thm], [])]
          |> filter_out (null o #2)
          |> map (fn (thmN, thms, attrs) =>
            ((qualify true (Binding.name thmN), attrs), [(thms, [])]));

        val (noted, lthy') = lthy
          |> Spec_Rules.add Binding.empty Spec_Rules.equational [casex] case_thms
          |> fold (uncurry (Spec_Rules.add Binding.empty Spec_Rules.equational))
            (AList.group (eq_list (op aconv)) (map (`(single o lhs_head_of)) all_sel_thms))
          |> fold (uncurry (Spec_Rules.add Binding.empty Spec_Rules.equational))
            (filter_out (null o snd) (map single discs ~~ nontriv_disc_eq_thmss))
          |> Local_Theory.declaration {syntax = false, pervasive = true, pos = \<^here>}
            (fn phi => Case_Translation.register
               (Morphism.term phi casex) (map (Morphism.term phi) ctrs))
          |> plugins code_plugin ?
             (Code.declare_default_eqns (map (rpair true) (flat nontriv_disc_eq_thmss @ case_thms @ all_sel_thms))
             #> Local_Theory.declaration {syntax = false, pervasive = false, pos = \<^here>}
               (fn phi => Context.mapping
                  (add_ctr_code fcT_name (map (Morphism.typ phi) As)
                     (map (dest_Const o Morphism.term phi) ctrs) (Morphism.fact phi inject_thms)
                     (Morphism.fact phi distinct_thms) (Morphism.fact phi case_thms))
                  I))
          |> Local_Theory.notes (anonymous_notes @ notes)
          (* for "datatype_realizer.ML": *)
          |>> name_noted_thms fcT_name exhaustN;

        val ctr_sugar =
          {kind = kind, T = fcT, ctrs = ctrs, casex = casex, discs = discs, selss = selss,
           exhaust = exhaust_thm, nchotomy = nchotomy_thm, injects = inject_thms,
           distincts = distinct_thms, case_thms = case_thms, case_cong = case_cong_thm,
           case_cong_weak = case_cong_weak_thm, case_distribs = [case_distrib_thm],
           split = split_thm, split_asm = split_asm_thm, disc_defs = nontriv_disc_defs,
           disc_thmss = disc_thmss, discIs = discI_thms, disc_eq_cases = disc_eq_case_thms,
           sel_defs = sel_defs, sel_thmss = sel_thmss, distinct_discsss = distinct_disc_thmsss,
           exhaust_discs = exhaust_disc_thms, exhaust_sels = exhaust_sel_thms,
           collapses = all_collapse_thms, expands = expand_thms, split_sels = split_sel_thms,
           split_sel_asms = split_sel_asm_thms, case_eq_ifs = case_eq_if_thms}
          |> morph_ctr_sugar (substitute_noted_thm noted);
      in
        (ctr_sugar, lthy' |> register_ctr_sugar plugins ctr_sugar)
      end;
  in
    (goalss, after_qed, lthy)
  end;

fun free_constructors kind tacss = (fn (goalss, after_qed, lthy) =>
  map2 (map2 (Thm.close_derivation \<^here> oo Goal.prove_sorry lthy [] [])) goalss tacss
  |> (fn thms => after_qed thms lthy)) oo prepare_free_constructors kind (K I) (K I);

fun free_constructors_cmd kind = (fn (goalss, after_qed, lthy) =>
  Proof.theorem NONE (snd oo after_qed) (map (map (rpair [])) goalss) lthy) oo
  prepare_free_constructors kind Plugin_Name.make_filter Syntax.read_term;

val parse_bound_term = Parse.binding --| \<^keyword>\<open>:\<close> -- Parse.term;

type ctr_options = Plugin_Name.filter * bool;
type ctr_options_cmd = (Proof.context -> Plugin_Name.filter) * bool;

val default_ctr_options : ctr_options = (Plugin_Name.default_filter, false);
val default_ctr_options_cmd : ctr_options_cmd = (K Plugin_Name.default_filter, false);

val parse_ctr_options =
  Scan.optional (\<^keyword>\<open>(\<close> |-- Parse.list1
        (Plugin_Name.parse_filter >> (apfst o K)
         || Parse.reserved "discs_sels" >> (apsnd o K o K true)) --|
      \<^keyword>\<open>)\<close>
      >> (fn fs => fold I fs default_ctr_options_cmd))
    default_ctr_options_cmd;

fun parse_ctr_spec parse_ctr parse_arg =
  parse_opt_binding_colon -- parse_ctr -- Scan.repeat parse_arg;

val parse_ctr_specs = Parse.enum1 "|" (parse_ctr_spec Parse.term Parse.binding);
val parse_sel_default_eqs = Scan.optional (\<^keyword>\<open>where\<close> |-- Parse.enum1 "|" Parse.prop) [];

val _ =
  Outer_Syntax.local_theory_to_proof \<^command_keyword>\<open>free_constructors\<close>
    "register an existing freely generated type's constructors"
    (parse_ctr_options -- Parse.binding --| \<^keyword>\<open>for\<close> -- parse_ctr_specs
       -- parse_sel_default_eqs
     >> free_constructors_cmd Unknown);



(** external views **)

(* document antiquotations *)

local

fun antiquote_setup binding co =
  Document_Output.antiquotation_pretty_source_embedded binding
    ((Scan.ahead (Scan.lift Parse.not_eof) >> Token.pos_of) --
      Args.type_name {proper = true, strict = true})
    (fn ctxt => fn (pos, type_name) =>
      let
        fun err () =
          error ("Bad " ^ Binding.name_of binding ^ ": " ^ quote type_name ^ Position.here pos);
      in
        (case ctr_sugar_of ctxt type_name of
          NONE => err ()
        | SOME {kind, T = T0, ctrs = ctrs0, ...} =>
            let
              val _ = if co = (kind = Codatatype) then () else err ();

              val T = Logic.unvarifyT_global T0;
              val ctrs = map Logic.unvarify_global ctrs0;

              val pretty_typ_bracket = Syntax.pretty_typ (Config.put pretty_priority 1001 ctxt);
              fun pretty_ctr ctr =
                Pretty.block (Pretty.breaks (Syntax.pretty_term ctxt ctr ::
                  map pretty_typ_bracket (binder_types (fastype_of ctr))));
            in
              Pretty.block (Pretty.keyword1 (Binding.name_of binding) :: Pretty.brk 1 ::
                Syntax.pretty_typ ctxt T :: Pretty.str " =" :: Pretty.brk 1 ::
                flat (separate [Pretty.brk 1, Pretty.str "| "] (map (single o pretty_ctr) ctrs)))
            end)
        end);

in

val _ =
  Theory.setup
   (antiquote_setup \<^binding>\<open>datatype\<close> false #>
    antiquote_setup \<^binding>\<open>codatatype\<close> true);

end;


(* theory export *)

val _ =
  (Theory.setup o Thy_Info.add_presentation) (fn context => fn thy =>
    if Export_Theory.export_enabled context then
      let
        val parents = map (Data.get o Context.Theory) (Theory.parents_of thy);
        val datatypes =
          (Data.get (Context.Theory thy), []) |-> Symtab.fold
            (fn (name, (pos, {kind, T, ctrs, ...})) =>
              if kind = Record orelse exists (fn tab => Symtab.defined tab name) parents then I
              else
                let
                  val pos_properties = Thy_Info.adjust_pos_properties context pos;
                  val typ = Logic.unvarifyT_global T;
                  val constrs = map Logic.unvarify_global ctrs;
                  val typargs = rev (fold Term.add_tfrees (Logic.mk_type typ :: constrs) []);
                  val constructors = map (fn t => (t, Term.type_of t)) constrs;
                in
                  cons (pos_properties, (name, (kind = Codatatype, (typargs, (typ, constructors)))))
                end);
      in
        if null datatypes then ()
        else
          Export_Theory.export_body thy "datatypes"
            let open XML.Encode Term_XML.Encode in
              list (pair properties (pair string (pair bool (pair (list (pair string sort))
                (pair typ (list (pair (term (Sign.consts_of thy)) typ))))))) datatypes
            end
      end
    else ());

end;

Messung V0.5 in Prozent
C=92 H=94 G=92

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.19Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.