src/Pure/Isar/code_unit.ML
changeset 28708 a1a436f09ec6
parent 28704 8703d17c5e68
child 29270 0eade173f77e
equal deleted inserted replaced
28707:548703affff5 28708:a1a436f09ec6
    36     -> string * ((string * sort) list * (string * typ list) list)
    36     -> string * ((string * sort) list * (string * typ list) list)
    37 
    37 
    38   (*defining equations*)
    38   (*defining equations*)
    39   val assert_eqn: theory -> thm -> thm
    39   val assert_eqn: theory -> thm -> thm
    40   val mk_eqn: theory -> thm -> thm * bool
    40   val mk_eqn: theory -> thm -> thm * bool
    41   val assert_linear: thm * bool -> thm * bool
    41   val assert_linear: (string -> bool) -> thm * bool -> thm * bool
    42   val const_eqn: thm -> string
    42   val const_eqn: thm -> string
    43   val const_typ_eqn: thm -> string * typ
    43   val const_typ_eqn: thm -> string * typ
    44   val head_eqn: theory -> thm -> string * ((string * sort) list * typ)
    44   val head_eqn: theory -> thm -> string * ((string * sort) list * typ)
    45   val expand_eta: theory -> int -> thm -> thm
    45   val expand_eta: theory -> int -> thm -> thm
    46   val rewrite_eqn: simpset -> thm -> thm
    46   val rewrite_eqn: simpset -> thm -> thm
   375     val (_, args) = (strip_comb o fst o Logic.dest_equals o Thm.plain_prop_of) thm;
   375     val (_, args) = (strip_comb o fst o Logic.dest_equals o Thm.plain_prop_of) thm;
   376     val linear = not (has_duplicates (op =)
   376     val linear = not (has_duplicates (op =)
   377       ((fold o fold_aterms) (fn Var (v, _) => cons v | _ => I) args []))
   377       ((fold o fold_aterms) (fn Var (v, _) => cons v | _ => I) args []))
   378   in (thm, linear) end;
   378   in (thm, linear) end;
   379 
   379 
   380 fun assert_linear (thm, false) = (thm, false)
   380 fun assert_pat is_cons thm =
   381   | assert_linear (thm, true) = if snd (add_linear thm) then (thm, true)
   381   let
       
   382     val args = (snd o strip_comb o fst o Logic.dest_equals o Thm.plain_prop_of) thm;
       
   383     val _ = (map o map_aterms) (fn t as Const (c, _) => if is_cons c then t
       
   384           else bad_thm ("Not a constructor on left hand side of equation: "
       
   385             ^ quote c ^ ",\n in equation\n" ^ Display.string_of_thm thm)
       
   386       | t => t) args;
       
   387   in thm end;
       
   388 
       
   389 fun assert_linear is_cons (thm, false) = (thm, false)
       
   390   | assert_linear is_cons (thm, true) = if snd (add_linear (assert_pat is_cons thm)) then (thm, true)
   382       else bad_thm
   391       else bad_thm
   383         ("Duplicate variables on left hand side of defining equation:\n"
   392         ("Duplicate variables on left hand side of defining equation:\n"
   384           ^ Display.string_of_thm thm);
   393           ^ Display.string_of_thm thm);
   385 
   394 
   386 
   395