src/Pure/primitive_defs.ML
changeset 63042 741263be960e
parent 63038 1fbad761c1ba
child 63395 734723445a8c
equal deleted inserted replaced
63041:cb495c4807b3 63042:741263be960e
     4 Primitive definition forms.
     4 Primitive definition forms.
     5 *)
     5 *)
     6 
     6 
     7 signature PRIMITIVE_DEFS =
     7 signature PRIMITIVE_DEFS =
     8 sig
     8 sig
     9   val dest_def: Proof.context -> (term -> bool) -> (string -> bool) option -> (string -> bool) ->
     9   val dest_def: Proof.context ->
       
    10     {check_head: term -> bool,
       
    11      check_free_lhs: string -> bool,
       
    12      check_free_rhs: string -> bool,
       
    13      check_tfree: string -> bool} ->
    10     term -> (term * term) * term
    14     term -> (term * term) * term
    11   val abs_def: term -> term * term
    15   val abs_def: term -> term * term
    12 end;
    16 end;
    13 
    17 
    14 structure Primitive_Defs: PRIMITIVE_DEFS =
    18 structure Primitive_Defs: PRIMITIVE_DEFS =
    18   | term_kind (Free _) = "free variable "
    22   | term_kind (Free _) = "free variable "
    19   | term_kind (Bound _) = "bound variable "
    23   | term_kind (Bound _) = "bound variable "
    20   | term_kind _ = "";
    24   | term_kind _ = "";
    21 
    25 
    22 (*c x == t[x] to !!x. c x == t[x]*)
    26 (*c x == t[x] to !!x. c x == t[x]*)
    23 fun dest_def ctxt check_head is_fixed is_fixedT eq =
    27 fun dest_def ctxt {check_head, check_free_lhs, check_free_rhs, check_tfree} eq =
    24   let
    28   let
    25     fun err msg = raise TERM (msg, [eq]);
    29     fun err msg = raise TERM (msg, [eq]);
    26     val eq_vars = Term.strip_all_vars eq;
    30     val eq_vars = Term.strip_all_vars eq;
    27     val eq_body = Term.strip_all_body eq;
    31     val eq_body = Term.strip_all_body eq;
    28 
    32 
    34     val lhs = Envir.beta_eta_contract raw_lhs;
    38     val lhs = Envir.beta_eta_contract raw_lhs;
    35     val (head, args) = Term.strip_comb lhs;
    39     val (head, args) = Term.strip_comb lhs;
    36     val head_tfrees = Term.add_tfrees head [];
    40     val head_tfrees = Term.add_tfrees head [];
    37 
    41 
    38     fun check_arg (Bound _) = true
    42     fun check_arg (Bound _) = true
    39       | check_arg (Free (x, _)) = is_none is_fixed orelse not (the is_fixed x)
    43       | check_arg (Free (x, _)) = check_free_lhs x
    40       | check_arg (Const ("Pure.type", Type ("itself", [TFree _]))) = true
    44       | check_arg (Const ("Pure.type", Type ("itself", [TFree _]))) = true
    41       | check_arg _ = false;
    45       | check_arg _ = false;
    42     fun close_arg (Bound _) t = t
    46     fun close_arg (Bound _) t = t
    43       | close_arg x t = Logic.all x t;
    47       | close_arg x t = Logic.all x t;
    44 
    48 
    45     val lhs_bads = filter_out check_arg args;
    49     val lhs_bads = filter_out check_arg args;
    46     val lhs_dups = duplicates (op aconv) args;
    50     val lhs_dups = duplicates (op aconv) args;
    47     val rhs_extras = Term.fold_aterms (fn v as Free (x, _) =>
    51     val rhs_extras = Term.fold_aterms (fn v as Free (x, _) =>
    48       if is_none is_fixed orelse the is_fixed x orelse member (op aconv) args v then I
    52       if check_free_rhs x orelse member (op aconv) args v then I
    49       else insert (op aconv) v | _ => I) rhs [];
    53       else insert (op aconv) v | _ => I) rhs [];
    50     val rhs_extrasT = Term.fold_aterms (Term.fold_types (fn v as TFree (a, S) =>
    54     val rhs_extrasT = Term.fold_aterms (Term.fold_types (fn v as TFree (a, S) =>
    51       if is_fixedT a orelse member (op =) head_tfrees (a, S) then I
    55       if check_tfree a orelse member (op =) head_tfrees (a, S) then I
    52       else insert (op =) v | _ => I)) rhs [];
    56       else insert (op =) v | _ => I)) rhs [];
    53   in
    57   in
    54     if not (check_head head) then
    58     if not (check_head head) then
    55       err ("Bad head of lhs: " ^ term_kind head ^ display_terms [head])
    59       err ("Bad head of lhs: " ^ term_kind head ^ display_terms [head])
    56     else if not (null lhs_bads) then
    60     else if not (null lhs_bads) then