src/HOL/Tools/Predicate_Compile/pred_compile_aux.ML
author bulwahn
Sat, 24 Oct 2009 16:55:42 +0200
changeset 33127 eb91ec1ef6f0
parent 33125 2fef4f9429f7
child 33130 7eac458c2b22
permissions -rw-r--r--
added option show_proof_trace
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     1
(* Author: Lukas Bulwahn, TU Muenchen
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     2
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     3
Auxilary functions for predicate compiler
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     4
*)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     5
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     6
structure Predicate_Compile_Aux =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     7
struct
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     8
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
     9
(* syntactic functions *)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    10
 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    11
fun is_equationlike_term (Const ("==", _) $ _ $ _) = true
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    12
  | is_equationlike_term (Const ("Trueprop", _) $ (Const ("op =", _) $ _ $ _)) = true
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    13
  | is_equationlike_term _ = false
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    14
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    15
val is_equationlike = is_equationlike_term o prop_of 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    16
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    17
fun is_pred_equation_term (Const ("==", _) $ u $ v) =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    18
  (fastype_of u = @{typ bool}) andalso (fastype_of v = @{typ bool})
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    19
  | is_pred_equation_term _ = false
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    20
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    21
val is_pred_equation = is_pred_equation_term o prop_of 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    22
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    23
fun is_intro_term constname t =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    24
  case fst (strip_comb (HOLogic.dest_Trueprop (Logic.strip_imp_concl t))) of
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    25
    Const (c, _) => c = constname
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    26
  | _ => false
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    27
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    28
fun is_intro constname t = is_intro_term constname (prop_of t)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    29
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    30
fun is_pred thy constname =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    31
  let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    32
    val T = (Sign.the_const_type thy constname)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    33
  in body_type T = @{typ "bool"} end;
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    34
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    35
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    36
fun is_predT (T as Type("fun", [_, _])) = (snd (strip_type T) = HOLogic.boolT)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    37
  | is_predT _ = false
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    38
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    39
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    40
(*** check if a term contains only constructor functions ***)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    41
fun is_constrt thy =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    42
  let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    43
    val cnstrs = flat (maps
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    44
      (map (fn (_, (Tname, _, cs)) => map (apsnd (rpair Tname o length)) cs) o #descr o snd)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    45
      (Symtab.dest (Datatype.get_all thy)));
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    46
    fun check t = (case strip_comb t of
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    47
        (Free _, []) => true
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    48
      | (Const (s, T), ts) => (case (AList.lookup (op =) cnstrs s, body_type T) of
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    49
            (SOME (i, Tname), Type (Tname', _)) => length ts = i andalso Tname = Tname' andalso forall check ts
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    50
          | _ => false)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    51
      | _ => false)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    52
  in check end;  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    53
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    54
fun strip_ex (Const ("Ex", _) $ Abs (x, T, t)) =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    55
  let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    56
    val (xTs, t') = strip_ex t
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    57
  in
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    58
    ((x, T) :: xTs, t')
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    59
  end
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    60
  | strip_ex t = ([], t)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    61
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    62
fun focus_ex t nctxt =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    63
  let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    64
    val ((xs, Ts), t') = apfst split_list (strip_ex t) 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    65
    val (xs', nctxt') = Name.variants xs nctxt;
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    66
    val ps' = xs' ~~ Ts;
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    67
    val vs = map Free ps';
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    68
    val t'' = Term.subst_bounds (rev vs, t');
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    69
  in ((ps', t''), nctxt') end;
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    70
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    71
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
    72
(* introduction rule combinators *)
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    73
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
    74
(* combinators to apply a function to all literals of an introduction rules *)
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    75
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    76
(*
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    77
fun map_atoms f intro = 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    78
*)
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
    79
33113
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 32668
diff changeset
    80
fun fold_atoms f intro s =
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 32668
diff changeset
    81
  let
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 32668
diff changeset
    82
    val (literals, head) = Logic.strip_horn intro
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 32668
diff changeset
    83
    fun appl t s = (case t of
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 32668
diff changeset
    84
      (@{term "Not"} $ t') => f t' s
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 32668
diff changeset
    85
      | _ => f t s)
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 32668
diff changeset
    86
  in fold appl (map HOLogic.dest_Trueprop literals) s end
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 32668
diff changeset
    87
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    88
fun fold_map_atoms f intro s =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    89
  let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    90
    val (literals, head) = Logic.strip_horn intro
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    91
    fun appl t s = (case t of
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    92
      (@{term "Not"} $ t') =>
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    93
        let
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    94
          val (t'', s') = f t' s
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    95
        in (@{term "Not"} $ t'', s') end
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    96
      | _ => f t s)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    97
    val (literals', s') = fold_map appl (map HOLogic.dest_Trueprop literals) s
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    98
  in
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
    99
    (Logic.list_implies (map HOLogic.mk_Trueprop literals', head), s')
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   100
  end;
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   101
  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   102
(*
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   103
fun equals_conv lhs_cv rhs_cv ct =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   104
  case Thm.term_of ct of
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   105
    Const ("==", _) $ _ $ _ => Conv.arg_conv cv ct  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   106
  | _ => error "equals_conv"  
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   107
*)
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   108
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   109
(* Different options for compiler *)
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   110
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   111
datatype options = Options of {  
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   112
  (*check_modes : (string * int list list) list,*)
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   113
  show_steps : bool,
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   114
  show_mode_inference : bool,
33127
eb91ec1ef6f0 added option show_proof_trace
bulwahn
parents: 33125
diff changeset
   115
  show_proof_trace : bool,
33125
2fef4f9429f7 added option show_intermediate_results
bulwahn
parents: 33124
diff changeset
   116
  show_intermediate_results : bool,
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   117
  (*
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   118
  inductify_functions : bool,
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   119
  *)
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   120
  inductify : bool,
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   121
  rpred : bool
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   122
};
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   123
33125
2fef4f9429f7 added option show_intermediate_results
bulwahn
parents: 33124
diff changeset
   124
fun show_steps (Options opt) = #show_steps opt
2fef4f9429f7 added option show_intermediate_results
bulwahn
parents: 33124
diff changeset
   125
fun show_intermediate_results (Options opt) = #show_intermediate_results opt
33127
eb91ec1ef6f0 added option show_proof_trace
bulwahn
parents: 33125
diff changeset
   126
fun show_proof_trace (Options opt) = #show_proof_trace opt
33125
2fef4f9429f7 added option show_intermediate_results
bulwahn
parents: 33124
diff changeset
   127
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   128
fun is_inductify (Options opt) = #inductify opt
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   129
fun is_rpred (Options opt) = #rpred opt
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   130
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   131
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   132
val default_options = Options {
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   133
  show_steps = false,
33125
2fef4f9429f7 added option show_intermediate_results
bulwahn
parents: 33124
diff changeset
   134
  show_intermediate_results = false,
33127
eb91ec1ef6f0 added option show_proof_trace
bulwahn
parents: 33125
diff changeset
   135
  show_proof_trace = false,
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   136
  show_mode_inference = false,
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   137
  inductify = false,
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   138
  rpred = false
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   139
}
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   140
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   141
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   142
fun print_step options s =
33125
2fef4f9429f7 added option show_intermediate_results
bulwahn
parents: 33124
diff changeset
   143
  if show_steps options then tracing s else ()
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33113
diff changeset
   144
  
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   145
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   146
(* tuple processing *)
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   147
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   148
fun expand_tuples thy intro =
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   149
  let
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   150
    fun rewrite_args [] (pats, intro_t, ctxt) = (pats, intro_t, ctxt)
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   151
      | rewrite_args (arg::args) (pats, intro_t, ctxt) = 
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   152
      (case HOLogic.strip_tupleT (fastype_of arg) of
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   153
        (Ts as _ :: _ :: _) =>
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   154
        let
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   155
          fun rewrite_arg' (Const ("Pair", _) $ _ $ t2, Type ("*", [_, T2]))
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   156
            (args, (pats, intro_t, ctxt)) = rewrite_arg' (t2, T2) (args, (pats, intro_t, ctxt))
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   157
            | rewrite_arg' (t, Type ("*", [T1, T2])) (args, (pats, intro_t, ctxt)) =
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   158
              let
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   159
                val ([x, y], ctxt') = Variable.variant_fixes ["x", "y"] ctxt
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   160
                val pat = (t, HOLogic.mk_prod (Free (x, T1), Free (y, T2)))
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   161
                val intro_t' = Pattern.rewrite_term thy [pat] [] intro_t
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   162
                val args' = map (Pattern.rewrite_term thy [pat] []) args
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   163
              in
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   164
                rewrite_arg' (Free (y, T2), T2) (args', (pat::pats, intro_t', ctxt'))
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   165
              end
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   166
            | rewrite_arg' _ (args, (pats, intro_t, ctxt)) = (args, (pats, intro_t, ctxt))
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   167
          val (args', (pats, intro_t', ctxt')) = rewrite_arg' (arg, fastype_of arg)
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   168
            (args, (pats, intro_t, ctxt))
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   169
        in
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   170
          rewrite_args args' (pats, intro_t', ctxt')
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   171
        end
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   172
      | _ => rewrite_args args (pats, intro_t, ctxt))
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   173
    fun rewrite_prem atom =
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   174
      let
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   175
        val (_, args) = strip_comb atom
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   176
      in rewrite_args args end
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   177
    val ctxt = ProofContext.init thy
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   178
    val (((T_insts, t_insts), [intro']), ctxt1) = Variable.import false [intro] ctxt
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   179
    val intro_t = prop_of intro'
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   180
    val concl = Logic.strip_imp_concl intro_t
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   181
    val (p, args) = strip_comb (HOLogic.dest_Trueprop concl)
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   182
    val (pats', intro_t', ctxt2) = rewrite_args args ([], intro_t, ctxt1)
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   183
    val (pats', intro_t', ctxt3) = 
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   184
      fold_atoms rewrite_prem intro_t' (pats', intro_t', ctxt2)
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   185
    fun rewrite_pat (ct1, ct2) =
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   186
      (ct1, cterm_of thy (Pattern.rewrite_term thy pats' [] (term_of ct2)))
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   187
    val t_insts' = map rewrite_pat t_insts
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   188
    val intro'' = Thm.instantiate (T_insts, t_insts') intro
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   189
    val [intro'''] = Variable.export ctxt3 ctxt [intro'']
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   190
    val intro'''' = Simplifier.full_simplify
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   191
      (HOL_basic_ss addsimps [@{thm fst_conv}, @{thm snd_conv}, @{thm Pair_eq}])
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   192
      intro'''
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   193
  in
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   194
    intro''''
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   195
  end
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   196
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   197
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   198
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents:
diff changeset
   199
end;