| 
64962
 | 
     1  | 
(*  Title:      HOL/Decision_Procs/Conversions.thy
  | 
| 
 | 
     2  | 
    Author:     Stefan Berghofer
  | 
| 
 | 
     3  | 
*)
  | 
| 
 | 
     4  | 
  | 
| 
 | 
     5  | 
theory Conversions
  | 
| 
 | 
     6  | 
imports Main
  | 
| 
 | 
     7  | 
begin
  | 
| 
 | 
     8  | 
  | 
| 
64998
 | 
     9  | 
ML \<open>
  | 
| 
64962
 | 
    10  | 
fun tactic_of_conv cv i st =
  | 
| 
 | 
    11  | 
  if i > Thm.nprems_of st then Seq.empty
  | 
| 
 | 
    12  | 
  else Seq.single (Conv.gconv_rule cv i st);
  | 
| 
 | 
    13  | 
  | 
| 
 | 
    14  | 
fun binop_conv cv cv' = Conv.combination_conv (Conv.arg_conv cv) cv';
  | 
| 
64998
 | 
    15  | 
\<close>
  | 
| 
64962
 | 
    16  | 
  | 
| 
64998
 | 
    17  | 
ML \<open>
  | 
| 
64962
 | 
    18  | 
fun err s ct =
  | 
| 
 | 
    19  | 
   error (s ^ ": " ^ Syntax.string_of_term_global (Thm.theory_of_cterm ct) (Thm.term_of ct));
  | 
| 
64998
 | 
    20  | 
\<close>
  | 
| 
64962
 | 
    21  | 
  | 
| 
 | 
    22  | 
attribute_setup meta =
  | 
| 
64998
 | 
    23  | 
  \<open>Scan.succeed (fn (ctxt, th) => (NONE, SOME (mk_meta_eq th)))\<close>
  | 
| 
 | 
    24  | 
  \<open>convert equality to meta equality\<close>
  | 
| 
64962
 | 
    25  | 
  | 
| 
64998
 | 
    26  | 
ML \<open>
  | 
| 
64962
 | 
    27  | 
fun strip_app ct = ct |> Drule.strip_comb |>> Thm.term_of |>> dest_Const |>> fst;
  | 
| 
 | 
    28  | 
  | 
| 
 | 
    29  | 
fun inst cTs cts th =
  | 
| 
 | 
    30  | 
  Thm.instantiate' (map SOME cTs) (map SOME cts) th;
  | 
| 
 | 
    31  | 
  | 
| 
 | 
    32  | 
fun transitive' eq eq' = Thm.transitive eq (eq' (Thm.rhs_of eq));
  | 
| 
 | 
    33  | 
  | 
| 
 | 
    34  | 
fun type_of_eqn eqn = Thm.ctyp_of_cterm (Thm.dest_arg1 (Thm.cprop_of eqn));
  | 
| 
 | 
    35  | 
  | 
| 
 | 
    36  | 
fun cong1 conv ct =
  | 
| 
 | 
    37  | 
  Thm.combination (Thm.reflexive (Thm.dest_fun ct)) (conv (Thm.dest_arg ct));
  | 
| 
 | 
    38  | 
  | 
| 
 | 
    39  | 
fun cong1' conv' conv ct =
  | 
| 
 | 
    40  | 
  let val eqn = conv (Thm.dest_arg ct)
  | 
| 
 | 
    41  | 
  in
  | 
| 
 | 
    42  | 
    Thm.transitive
  | 
| 
 | 
    43  | 
      (Thm.combination (Thm.reflexive (Thm.dest_fun ct)) eqn)
  | 
| 
 | 
    44  | 
      (conv' (Thm.rhs_of eqn))
  | 
| 
 | 
    45  | 
  end;
  | 
| 
 | 
    46  | 
  | 
| 
 | 
    47  | 
fun cong2 conv1 conv2 ct =
  | 
| 
 | 
    48  | 
  Thm.combination
  | 
| 
 | 
    49  | 
    (Thm.combination
  | 
| 
 | 
    50  | 
       (Thm.reflexive (Thm.dest_fun2 ct))
  | 
| 
 | 
    51  | 
       (conv1 (Thm.dest_arg1 ct)))
  | 
| 
 | 
    52  | 
    (conv2 (Thm.dest_arg ct));
  | 
| 
 | 
    53  | 
  | 
| 
 | 
    54  | 
fun cong2' conv conv1 conv2 ct =
  | 
| 
 | 
    55  | 
  let
  | 
| 
 | 
    56  | 
    val eqn1 = conv1 (Thm.dest_arg1 ct);
  | 
| 
 | 
    57  | 
    val eqn2 = conv2 (Thm.dest_arg ct)
  | 
| 
 | 
    58  | 
  in
  | 
| 
 | 
    59  | 
    Thm.transitive
  | 
| 
 | 
    60  | 
      (Thm.combination
  | 
| 
 | 
    61  | 
         (Thm.combination (Thm.reflexive (Thm.dest_fun2 ct)) eqn1)
  | 
| 
 | 
    62  | 
         eqn2)
  | 
| 
 | 
    63  | 
      (conv (Thm.rhs_of eqn1) (Thm.rhs_of eqn2))
  | 
| 
 | 
    64  | 
  end;
  | 
| 
 | 
    65  | 
  | 
| 
 | 
    66  | 
fun cong2'' conv eqn1 eqn2 =
  | 
| 
 | 
    67  | 
  let val eqn3 = conv (Thm.rhs_of eqn1) (Thm.rhs_of eqn2)
  | 
| 
 | 
    68  | 
  in
  | 
| 
 | 
    69  | 
    Thm.transitive
  | 
| 
 | 
    70  | 
      (Thm.combination
  | 
| 
 | 
    71  | 
         (Thm.combination (Thm.reflexive (Thm.dest_fun2 (Thm.lhs_of eqn3))) eqn1)
  | 
| 
 | 
    72  | 
         eqn2)
  | 
| 
 | 
    73  | 
      eqn3
  | 
| 
 | 
    74  | 
  end;
  | 
| 
 | 
    75  | 
  | 
| 
 | 
    76  | 
fun args1 conv ct = conv (Thm.dest_arg ct);
  | 
| 
 | 
    77  | 
fun args2 conv ct = conv (Thm.dest_arg1 ct) (Thm.dest_arg ct);
  | 
| 
64998
 | 
    78  | 
\<close>
  | 
| 
64962
 | 
    79  | 
  | 
| 
64998
 | 
    80  | 
ML \<open>
  | 
| 
64962
 | 
    81  | 
fun strip_numeral ct = (case strip_app ct of
  | 
| 
69597
 | 
    82  | 
    (\<^const_name>\<open>uminus\<close>, [n]) => (case strip_app n of
  | 
| 
 | 
    83  | 
      (\<^const_name>\<open>numeral\<close>, [b]) => (\<^const_name>\<open>uminus\<close>, [b])
  | 
| 
64962
 | 
    84  | 
    | _ => ("", []))
 | 
| 
 | 
    85  | 
  | x => x);
  | 
| 
64998
 | 
    86  | 
\<close>
  | 
| 
64962
 | 
    87  | 
  | 
| 
 | 
    88  | 
lemma nat_minus1_eq: "nat (- 1) = 0"
  | 
| 
 | 
    89  | 
  by simp
  | 
| 
 | 
    90  | 
  | 
| 
64998
 | 
    91  | 
ML \<open>
  | 
| 
64962
 | 
    92  | 
fun nat_conv i = (case strip_app i of
  | 
| 
69597
 | 
    93  | 
    (\<^const_name>\<open>zero_class.zero\<close>, []) => @{thm nat_0 [meta]}
 | 
| 
 | 
    94  | 
  | (\<^const_name>\<open>one_class.one\<close>, []) => @{thm nat_one_as_int [meta, symmetric]}
 | 
| 
 | 
    95  | 
  | (\<^const_name>\<open>numeral\<close>, [b]) => inst [] [b] @{thm nat_numeral [meta]}
 | 
| 
 | 
    96  | 
  | (\<^const_name>\<open>uminus\<close>, [b]) => (case strip_app b of
  | 
| 
 | 
    97  | 
      (\<^const_name>\<open>one_class.one\<close>, []) => @{thm nat_minus1_eq [meta]}
 | 
| 
 | 
    98  | 
    | (\<^const_name>\<open>numeral\<close>, [b']) => inst [] [b'] @{thm nat_neg_numeral [meta]}));
 | 
| 
64998
 | 
    99  | 
\<close>
  | 
| 
64962
 | 
   100  | 
  | 
| 
64998
 | 
   101  | 
ML \<open>
  | 
| 
64962
 | 
   102  | 
fun add_num_conv b b' = (case (strip_app b, strip_app b') of
  | 
| 
69597
 | 
   103  | 
    ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   104  | 
      @{thm add_num_simps(1) [meta]}
 | 
| 
69597
 | 
   105  | 
  | ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   106  | 
      inst [] [n] @{thm add_num_simps(2) [meta]}
 | 
| 
69597
 | 
   107  | 
  | ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   108  | 
      transitive'
  | 
| 
 | 
   109  | 
        (inst [] [n] @{thm add_num_simps(3) [meta]})
 | 
| 
 | 
   110  | 
        (cong1 (args2 add_num_conv))
  | 
| 
69597
 | 
   111  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   112  | 
      inst [] [m] @{thm add_num_simps(4) [meta]}
 | 
| 
69597
 | 
   113  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   114  | 
      transitive'
  | 
| 
 | 
   115  | 
        (inst [] [m, n] @{thm add_num_simps(5) [meta]})
 | 
| 
 | 
   116  | 
        (cong1 (args2 add_num_conv))
  | 
| 
69597
 | 
   117  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   118  | 
      transitive'
  | 
| 
 | 
   119  | 
        (inst [] [m, n] @{thm add_num_simps(6) [meta]})
 | 
| 
 | 
   120  | 
        (cong1 (args2 add_num_conv))
  | 
| 
69597
 | 
   121  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   122  | 
      transitive'
  | 
| 
 | 
   123  | 
        (inst [] [m] @{thm add_num_simps(7) [meta]})
 | 
| 
 | 
   124  | 
        (cong1 (args2 add_num_conv))
  | 
| 
69597
 | 
   125  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   126  | 
      transitive'
  | 
| 
 | 
   127  | 
        (inst [] [m, n] @{thm add_num_simps(8) [meta]})
 | 
| 
 | 
   128  | 
        (cong1 (args2 add_num_conv))
  | 
| 
69597
 | 
   129  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   130  | 
      transitive'
  | 
| 
 | 
   131  | 
        (inst [] [m, n] @{thm add_num_simps(9) [meta]})
 | 
| 
 | 
   132  | 
        (cong1 (cong2' add_num_conv (args2 add_num_conv) Thm.reflexive)));
  | 
| 
64998
 | 
   133  | 
\<close>
  | 
| 
64962
 | 
   134  | 
  | 
| 
64998
 | 
   135  | 
ML \<open>
  | 
| 
64962
 | 
   136  | 
fun BitM_conv m = (case strip_app m of
  | 
| 
69597
 | 
   137  | 
    (\<^const_name>\<open>Num.One\<close>, []) => @{thm BitM.simps(1) [meta]}
 | 
| 
 | 
   138  | 
  | (\<^const_name>\<open>Num.Bit0\<close>, [n]) =>
  | 
| 
64962
 | 
   139  | 
      transitive'
  | 
| 
 | 
   140  | 
        (inst [] [n] @{thm BitM.simps(2) [meta]})
 | 
| 
 | 
   141  | 
        (cong1 (args1 BitM_conv))
  | 
| 
69597
 | 
   142  | 
  | (\<^const_name>\<open>Num.Bit1\<close>, [n]) =>
  | 
| 
64962
 | 
   143  | 
      inst [] [n] @{thm BitM.simps(3) [meta]});
 | 
| 
64998
 | 
   144  | 
\<close>
  | 
| 
64962
 | 
   145  | 
  | 
| 
 | 
   146  | 
lemma dbl_neg_numeral:
  | 
| 
 | 
   147  | 
  "Num.dbl (- Num.numeral k) = - Num.numeral (Num.Bit0 k)"
  | 
| 
 | 
   148  | 
  by simp
  | 
| 
 | 
   149  | 
  | 
| 
64998
 | 
   150  | 
ML \<open>
  | 
| 
64962
 | 
   151  | 
fun dbl_conv a =
  | 
| 
 | 
   152  | 
  let
  | 
| 
 | 
   153  | 
    val dbl_neg_numeral_a = inst [a] [] @{thm dbl_neg_numeral [meta]};
 | 
| 
 | 
   154  | 
    val dbl_0_a = inst [a] [] @{thm dbl_simps(2) [meta]};
 | 
| 
 | 
   155  | 
    val dbl_numeral_a = inst [a] [] @{thm dbl_simps(5) [meta]}
 | 
| 
 | 
   156  | 
  in
  | 
| 
 | 
   157  | 
    fn n =>
  | 
| 
 | 
   158  | 
      case strip_numeral n of
  | 
| 
69597
 | 
   159  | 
        (\<^const_name>\<open>zero_class.zero\<close>, []) => dbl_0_a
  | 
| 
 | 
   160  | 
      | (\<^const_name>\<open>numeral\<close>, [k]) => inst [] [k] dbl_numeral_a
  | 
| 
 | 
   161  | 
      | (\<^const_name>\<open>uminus\<close>, [k]) => inst [] [k] dbl_neg_numeral_a
  | 
| 
64962
 | 
   162  | 
  end;
  | 
| 
64998
 | 
   163  | 
\<close>
  | 
| 
64962
 | 
   164  | 
  | 
| 
 | 
   165  | 
lemma dbl_inc_neg_numeral:
  | 
| 
 | 
   166  | 
  "Num.dbl_inc (- Num.numeral k) = - Num.numeral (Num.BitM k)"
  | 
| 
 | 
   167  | 
  by simp
  | 
| 
 | 
   168  | 
  | 
| 
64998
 | 
   169  | 
ML \<open>
  | 
| 
64962
 | 
   170  | 
fun dbl_inc_conv a =
  | 
| 
 | 
   171  | 
  let
  | 
| 
 | 
   172  | 
    val dbl_inc_neg_numeral_a = inst [a] [] @{thm dbl_inc_neg_numeral [meta]};
 | 
| 
 | 
   173  | 
    val dbl_inc_0_a = inst [a] [] @{thm dbl_inc_simps(2) [folded numeral_One, meta]};
 | 
| 
 | 
   174  | 
    val dbl_inc_numeral_a = inst [a] [] @{thm dbl_inc_simps(5) [meta]};
 | 
| 
 | 
   175  | 
  in
  | 
| 
 | 
   176  | 
    fn n =>
  | 
| 
 | 
   177  | 
      case strip_numeral n of
  | 
| 
69597
 | 
   178  | 
        (\<^const_name>\<open>zero_class.zero\<close>, []) => dbl_inc_0_a
  | 
| 
 | 
   179  | 
      | (\<^const_name>\<open>numeral\<close>, [k]) => inst [] [k] dbl_inc_numeral_a
  | 
| 
 | 
   180  | 
      | (\<^const_name>\<open>uminus\<close>, [k]) =>
  | 
| 
64962
 | 
   181  | 
          transitive'
  | 
| 
 | 
   182  | 
            (inst [] [k] dbl_inc_neg_numeral_a)
  | 
| 
 | 
   183  | 
            (cong1 (cong1 (args1 BitM_conv)))
  | 
| 
 | 
   184  | 
  end;
  | 
| 
64998
 | 
   185  | 
\<close>
  | 
| 
64962
 | 
   186  | 
  | 
| 
 | 
   187  | 
lemma dbl_dec_neg_numeral:
  | 
| 
 | 
   188  | 
  "Num.dbl_dec (- Num.numeral k) = - Num.numeral (Num.Bit1 k)"
  | 
| 
 | 
   189  | 
  by simp
  | 
| 
 | 
   190  | 
  | 
| 
64998
 | 
   191  | 
ML \<open>
  | 
| 
64962
 | 
   192  | 
fun dbl_dec_conv a =
  | 
| 
 | 
   193  | 
  let
  | 
| 
 | 
   194  | 
    val dbl_dec_neg_numeral_a = inst [a] [] @{thm dbl_dec_neg_numeral [meta]};
 | 
| 
 | 
   195  | 
    val dbl_dec_0_a = inst [a] [] @{thm dbl_dec_simps(2) [folded numeral_One, meta]};
 | 
| 
 | 
   196  | 
    val dbl_dec_numeral_a = inst [a] [] @{thm dbl_dec_simps(5) [meta]};
 | 
| 
 | 
   197  | 
  in
  | 
| 
 | 
   198  | 
    fn n =>
  | 
| 
 | 
   199  | 
      case strip_numeral n of
  | 
| 
69597
 | 
   200  | 
        (\<^const_name>\<open>zero_class.zero\<close>, []) => dbl_dec_0_a
  | 
| 
 | 
   201  | 
      | (\<^const_name>\<open>uminus\<close>, [k]) => inst [] [k] dbl_dec_neg_numeral_a
  | 
| 
 | 
   202  | 
      | (\<^const_name>\<open>numeral\<close>, [k]) =>
  | 
| 
64962
 | 
   203  | 
          transitive'
  | 
| 
 | 
   204  | 
            (inst [] [k] dbl_dec_numeral_a)
  | 
| 
 | 
   205  | 
            (cong1 (args1 BitM_conv))
  | 
| 
 | 
   206  | 
  end;
  | 
| 
64998
 | 
   207  | 
\<close>
  | 
| 
64962
 | 
   208  | 
  | 
| 
64998
 | 
   209  | 
ML \<open>
  | 
| 
64962
 | 
   210  | 
fun sub_conv a =
  | 
| 
 | 
   211  | 
  let
  | 
| 
 | 
   212  | 
    val [sub_One_One, sub_One_Bit0, sub_One_Bit1,
  | 
| 
 | 
   213  | 
         sub_Bit0_One, sub_Bit1_One, sub_Bit0_Bit0,
  | 
| 
 | 
   214  | 
         sub_Bit0_Bit1, sub_Bit1_Bit0, sub_Bit1_Bit1] =
  | 
| 
 | 
   215  | 
      map (inst [a] []) @{thms sub_num_simps [meta]};
 | 
| 
 | 
   216  | 
    val dbl_conv_a = dbl_conv a;
  | 
| 
 | 
   217  | 
    val dbl_inc_conv_a = dbl_inc_conv a;
  | 
| 
 | 
   218  | 
    val dbl_dec_conv_a = dbl_dec_conv a;
  | 
| 
 | 
   219  | 
  | 
| 
 | 
   220  | 
    fun conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   221  | 
        ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   222  | 
          sub_One_One
  | 
| 
69597
 | 
   223  | 
      | ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.Bit0\<close>, [l])) =>
  | 
| 
64962
 | 
   224  | 
          transitive'
  | 
| 
 | 
   225  | 
            (inst [] [l] sub_One_Bit0)
  | 
| 
 | 
   226  | 
            (cong1 (cong1 (args1 BitM_conv)))
  | 
| 
69597
 | 
   227  | 
      | ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.Bit1\<close>, [l])) =>
  | 
| 
64962
 | 
   228  | 
          inst [] [l] sub_One_Bit1
  | 
| 
69597
 | 
   229  | 
      | ((\<^const_name>\<open>Num.Bit0\<close>, [k]), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   230  | 
          transitive'
  | 
| 
 | 
   231  | 
            (inst [] [k] sub_Bit0_One)
  | 
| 
 | 
   232  | 
            (cong1 (args1 BitM_conv))
  | 
| 
69597
 | 
   233  | 
      | ((\<^const_name>\<open>Num.Bit1\<close>, [k]), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   234  | 
          inst [] [k] sub_Bit1_One
  | 
| 
69597
 | 
   235  | 
      | ((\<^const_name>\<open>Num.Bit0\<close>, [k]), (\<^const_name>\<open>Num.Bit0\<close>, [l])) =>
  | 
| 
64962
 | 
   236  | 
          transitive'
  | 
| 
 | 
   237  | 
            (inst [] [k, l] sub_Bit0_Bit0)
  | 
| 
 | 
   238  | 
            (cong1' dbl_conv_a (args2 conv))
  | 
| 
69597
 | 
   239  | 
      | ((\<^const_name>\<open>Num.Bit0\<close>, [k]), (\<^const_name>\<open>Num.Bit1\<close>, [l])) =>
  | 
| 
64962
 | 
   240  | 
          transitive'
  | 
| 
 | 
   241  | 
            (inst [] [k, l] sub_Bit0_Bit1)
  | 
| 
 | 
   242  | 
            (cong1' dbl_dec_conv_a (args2 conv))
  | 
| 
69597
 | 
   243  | 
      | ((\<^const_name>\<open>Num.Bit1\<close>, [k]), (\<^const_name>\<open>Num.Bit0\<close>, [l])) =>
  | 
| 
64962
 | 
   244  | 
          transitive'
  | 
| 
 | 
   245  | 
            (inst [] [k, l] sub_Bit1_Bit0)
  | 
| 
 | 
   246  | 
            (cong1' dbl_inc_conv_a (args2 conv))
  | 
| 
69597
 | 
   247  | 
      | ((\<^const_name>\<open>Num.Bit1\<close>, [k]), (\<^const_name>\<open>Num.Bit1\<close>, [l])) =>
  | 
| 
64962
 | 
   248  | 
          transitive'
  | 
| 
 | 
   249  | 
            (inst [] [k, l] sub_Bit1_Bit1)
  | 
| 
 | 
   250  | 
            (cong1' dbl_conv_a (args2 conv)))
  | 
| 
 | 
   251  | 
  in conv end;
  | 
| 
64998
 | 
   252  | 
\<close>
  | 
| 
64962
 | 
   253  | 
  | 
| 
64998
 | 
   254  | 
ML \<open>
  | 
| 
64962
 | 
   255  | 
fun expand1 a =
  | 
| 
 | 
   256  | 
  let val numeral_1_eq_1_a = inst [a] [] @{thm numeral_One [meta, symmetric]}
 | 
| 
 | 
   257  | 
  in
  | 
| 
 | 
   258  | 
    fn n =>
  | 
| 
 | 
   259  | 
      case Thm.term_of n of
  | 
| 
69597
 | 
   260  | 
        Const (\<^const_name>\<open>one_class.one\<close>, _) => numeral_1_eq_1_a
  | 
| 
 | 
   261  | 
      | Const (\<^const_name>\<open>uminus\<close>, _) $ Const (\<^const_name>\<open>one_class.one\<close>, _) =>
  | 
| 
64962
 | 
   262  | 
          Thm.combination (Thm.reflexive (Thm.dest_fun n)) numeral_1_eq_1_a
  | 
| 
69597
 | 
   263  | 
      | Const (\<^const_name>\<open>zero_class.zero\<close>, _) => Thm.reflexive n
  | 
| 
 | 
   264  | 
      | Const (\<^const_name>\<open>numeral\<close>, _) $ _ => Thm.reflexive n
  | 
| 
 | 
   265  | 
      | Const (\<^const_name>\<open>uminus\<close>, _) $
  | 
| 
 | 
   266  | 
          (Const (\<^const_name>\<open>numeral\<close>, _) $ _) => Thm.reflexive n
  | 
| 
64962
 | 
   267  | 
      | _ => err "expand1" n
  | 
| 
 | 
   268  | 
  end;
  | 
| 
 | 
   269  | 
  | 
| 
 | 
   270  | 
fun norm1_eq a =
  | 
| 
 | 
   271  | 
  let val numeral_1_eq_1_a = inst [a] [] @{thm numeral_One [meta]}
 | 
| 
 | 
   272  | 
  in
  | 
| 
 | 
   273  | 
    fn eq =>
  | 
| 
 | 
   274  | 
      case Thm.term_of (Thm.rhs_of eq) of
  | 
| 
69597
 | 
   275  | 
        Const (\<^const_name>\<open>Num.numeral\<close>, _) $ Const (\<^const_name>\<open>Num.One\<close>, _) =>
  | 
| 
64962
 | 
   276  | 
          Thm.transitive eq numeral_1_eq_1_a
  | 
| 
69597
 | 
   277  | 
      | Const (\<^const_name>\<open>uminus\<close>, _) $
  | 
| 
 | 
   278  | 
          (Const (\<^const_name>\<open>Num.numeral\<close>, _) $ Const (\<^const_name>\<open>Num.One\<close>, _)) =>
  | 
| 
64962
 | 
   279  | 
            Thm.transitive eq
  | 
| 
 | 
   280  | 
              (Thm.combination (Thm.reflexive (Thm.dest_fun (Thm.rhs_of eq)))
  | 
| 
 | 
   281  | 
                 numeral_1_eq_1_a)
  | 
| 
 | 
   282  | 
      | _ => eq
  | 
| 
 | 
   283  | 
  end;
  | 
| 
64998
 | 
   284  | 
\<close>
  | 
| 
64962
 | 
   285  | 
  | 
| 
64998
 | 
   286  | 
ML \<open>
  | 
| 
64962
 | 
   287  | 
fun plus_conv f a =
  | 
| 
 | 
   288  | 
  let
  | 
| 
 | 
   289  | 
    val add_0_a = inst [a] [] @{thm add_0 [meta]};
 | 
| 
 | 
   290  | 
    val add_0_right_a = inst [a] [] @{thm add_0_right [meta]};
 | 
| 
 | 
   291  | 
    val numeral_plus_numeral_a = inst [a] [] @{thm numeral_plus_numeral [meta]};
 | 
| 
 | 
   292  | 
    val expand1_a = expand1 a;
  | 
| 
 | 
   293  | 
  | 
| 
 | 
   294  | 
    fun conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   295  | 
        ((\<^const_name>\<open>zero_class.zero\<close>, []), _) => inst [] [n] add_0_a
  | 
| 
 | 
   296  | 
      | (_, (\<^const_name>\<open>zero_class.zero\<close>, [])) => inst [] [m] add_0_right_a
  | 
| 
 | 
   297  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   298  | 
          transitive'
  | 
| 
 | 
   299  | 
            (inst [] [m, n] numeral_plus_numeral_a)
  | 
| 
 | 
   300  | 
            (cong1 (args2 add_num_conv))
  | 
| 
 | 
   301  | 
      | _ => cong2'' (f conv) (expand1_a m) (expand1_a n))
  | 
| 
 | 
   302  | 
  in f conv end;
  | 
| 
 | 
   303  | 
  | 
| 
69597
 | 
   304  | 
val nat_plus_conv = plus_conv I \<^ctyp>\<open>nat\<close>;
  | 
| 
64998
 | 
   305  | 
\<close>
  | 
| 
64962
 | 
   306  | 
  | 
| 
 | 
   307  | 
lemma neg_numeral_plus_neg_numeral:
  | 
| 
 | 
   308  | 
  "- Num.numeral m + - Num.numeral n = (- Num.numeral (m + n) ::'a::neg_numeral)"
  | 
| 
 | 
   309  | 
  by simp
  | 
| 
 | 
   310  | 
  | 
| 
64998
 | 
   311  | 
ML \<open>
  | 
| 
64962
 | 
   312  | 
fun plus_neg_conv a =
  | 
| 
 | 
   313  | 
  let
  | 
| 
 | 
   314  | 
    val numeral_plus_neg_numeral_a =
  | 
| 
 | 
   315  | 
      inst [a] [] @{thm add_neg_numeral_simps(1) [meta]};
 | 
| 
 | 
   316  | 
    val neg_numeral_plus_numeral_a =
  | 
| 
 | 
   317  | 
      inst [a] [] @{thm add_neg_numeral_simps(2) [meta]};
 | 
| 
 | 
   318  | 
    val neg_numeral_plus_neg_numeral_a =
  | 
| 
 | 
   319  | 
      inst [a] [] @{thm neg_numeral_plus_neg_numeral [meta]};
 | 
| 
 | 
   320  | 
    val sub_conv_a = sub_conv a;
  | 
| 
 | 
   321  | 
  in
  | 
| 
 | 
   322  | 
    fn conv => fn m => fn n => 
  | 
| 
 | 
   323  | 
      case (strip_numeral m, strip_numeral n) of
  | 
| 
69597
 | 
   324  | 
        ((\<^const_name>\<open>Num.numeral\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   325  | 
          Thm.transitive
  | 
| 
 | 
   326  | 
            (inst [] [m, n] numeral_plus_neg_numeral_a)
  | 
| 
 | 
   327  | 
            (sub_conv_a m n)
  | 
| 
69597
 | 
   328  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>Num.numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   329  | 
          Thm.transitive
  | 
| 
 | 
   330  | 
            (inst [] [m, n] neg_numeral_plus_numeral_a)
  | 
| 
 | 
   331  | 
            (sub_conv_a n m)
  | 
| 
69597
 | 
   332  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   333  | 
          transitive'
  | 
| 
 | 
   334  | 
            (inst [] [m, n] neg_numeral_plus_neg_numeral_a)
  | 
| 
 | 
   335  | 
            (cong1 (cong1 (args2 add_num_conv)))
  | 
| 
 | 
   336  | 
      | _ => conv m n
  | 
| 
 | 
   337  | 
  end;
  | 
| 
 | 
   338  | 
  | 
| 
 | 
   339  | 
fun plus_conv' a = norm1_eq a oo plus_conv (plus_neg_conv a) a;
  | 
| 
 | 
   340  | 
  | 
| 
69597
 | 
   341  | 
val int_plus_conv = plus_conv' \<^ctyp>\<open>int\<close>;
  | 
| 
64998
 | 
   342  | 
\<close>
  | 
| 
64962
 | 
   343  | 
  | 
| 
 | 
   344  | 
lemma minus_one: "- 1 = - 1" by simp
  | 
| 
 | 
   345  | 
lemma minus_numeral: "- numeral b = - numeral b" by simp
  | 
| 
 | 
   346  | 
  | 
| 
64998
 | 
   347  | 
ML \<open>
  | 
| 
64962
 | 
   348  | 
fun uminus_conv a =
  | 
| 
 | 
   349  | 
  let
  | 
| 
 | 
   350  | 
    val minus_zero_a = inst [a] [] @{thm minus_zero [meta]};
 | 
| 
 | 
   351  | 
    val minus_one_a = inst [a] [] @{thm minus_one [meta]};
 | 
| 
 | 
   352  | 
    val minus_numeral_a = inst [a] [] @{thm minus_numeral [meta]};
 | 
| 
 | 
   353  | 
    val minus_minus_a = inst [a] [] @{thm minus_minus [meta]}
 | 
| 
 | 
   354  | 
  in
  | 
| 
 | 
   355  | 
    fn n =>
  | 
| 
 | 
   356  | 
      case strip_app n of
  | 
| 
69597
 | 
   357  | 
        (\<^const_name>\<open>zero_class.zero\<close>, []) => minus_zero_a
  | 
| 
 | 
   358  | 
      | (\<^const_name>\<open>one_class.one\<close>, []) => minus_one_a
  | 
| 
 | 
   359  | 
      | (\<^const_name>\<open>Num.numeral\<close>, [m]) => inst [] [m] minus_numeral_a
  | 
| 
 | 
   360  | 
      | (\<^const_name>\<open>uminus\<close>, [m]) => inst [] [m] minus_minus_a
  | 
| 
64962
 | 
   361  | 
  end;
  | 
| 
 | 
   362  | 
  | 
| 
69597
 | 
   363  | 
val int_neg_conv = uminus_conv \<^ctyp>\<open>int\<close>;
  | 
| 
64998
 | 
   364  | 
\<close>
  | 
| 
64962
 | 
   365  | 
  | 
| 
64998
 | 
   366  | 
ML \<open>
  | 
| 
64962
 | 
   367  | 
fun minus_conv a =
  | 
| 
 | 
   368  | 
  let
  | 
| 
 | 
   369  | 
    val [numeral_minus_numeral_a, numeral_minus_neg_numeral_a,
  | 
| 
 | 
   370  | 
         neg_numeral_minus_numeral_a, neg_numeral_minus_neg_numeral_a] =
  | 
| 
 | 
   371  | 
      map (inst [a] []) @{thms diff_numeral_simps [meta]};
 | 
| 
 | 
   372  | 
    val diff_0_a = inst [a] [] @{thm diff_0 [meta]};
 | 
| 
 | 
   373  | 
    val diff_0_right_a = inst [a] [] @{thm diff_0_right [meta]};
 | 
| 
 | 
   374  | 
    val sub_conv_a = sub_conv a;
  | 
| 
 | 
   375  | 
    val uminus_conv_a = uminus_conv a;
  | 
| 
 | 
   376  | 
    val expand1_a = expand1 a;
  | 
| 
 | 
   377  | 
    val norm1_eq_a = norm1_eq a;
  | 
| 
 | 
   378  | 
  | 
| 
 | 
   379  | 
    fun conv m n = (case (strip_numeral m, strip_numeral n) of
  | 
| 
69597
 | 
   380  | 
        ((\<^const_name>\<open>zero_class.zero\<close>, []), _) =>
  | 
| 
64962
 | 
   381  | 
          Thm.transitive (inst [] [n] diff_0_a) (uminus_conv_a n)
  | 
| 
69597
 | 
   382  | 
      | (_, (\<^const_name>\<open>zero_class.zero\<close>, [])) => inst [] [m] diff_0_right_a
  | 
| 
 | 
   383  | 
      | ((\<^const_name>\<open>Num.numeral\<close>, [m]), (\<^const_name>\<open>Num.numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   384  | 
          Thm.transitive
  | 
| 
 | 
   385  | 
            (inst [] [m, n] numeral_minus_numeral_a)
  | 
| 
 | 
   386  | 
            (sub_conv_a m n)
  | 
| 
69597
 | 
   387  | 
      | ((\<^const_name>\<open>Num.numeral\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   388  | 
          transitive'
  | 
| 
 | 
   389  | 
            (inst [] [m, n] numeral_minus_neg_numeral_a)
  | 
| 
 | 
   390  | 
            (cong1 (args2 add_num_conv))
  | 
| 
69597
 | 
   391  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>Num.numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   392  | 
          transitive'
  | 
| 
 | 
   393  | 
            (inst [] [m, n] neg_numeral_minus_numeral_a)
  | 
| 
 | 
   394  | 
            (cong1 (cong1 (args2 add_num_conv)))
  | 
| 
69597
 | 
   395  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   396  | 
          Thm.transitive
  | 
| 
 | 
   397  | 
            (inst [] [m, n] neg_numeral_minus_neg_numeral_a)
  | 
| 
 | 
   398  | 
            (sub_conv_a n m)
  | 
| 
 | 
   399  | 
      | _ => cong2'' conv (expand1_a m) (expand1_a n))
  | 
| 
 | 
   400  | 
  in norm1_eq_a oo conv end;
  | 
| 
 | 
   401  | 
  | 
| 
69597
 | 
   402  | 
val int_minus_conv = minus_conv \<^ctyp>\<open>int\<close>;
  | 
| 
64998
 | 
   403  | 
\<close>
  | 
| 
64962
 | 
   404  | 
  | 
| 
64998
 | 
   405  | 
ML \<open>
  | 
| 
69597
 | 
   406  | 
val int_numeral = Thm.apply \<^cterm>\<open>numeral :: num \<Rightarrow> int\<close>;
  | 
| 
64962
 | 
   407  | 
  | 
| 
69597
 | 
   408  | 
val nat_minus_refl = Thm.reflexive \<^cterm>\<open>minus :: nat \<Rightarrow> nat \<Rightarrow> nat\<close>;
  | 
| 
64962
 | 
   409  | 
  | 
| 
69597
 | 
   410  | 
val expand1_nat = expand1 \<^ctyp>\<open>nat\<close>;
  | 
| 
64962
 | 
   411  | 
  | 
| 
 | 
   412  | 
fun nat_minus_conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   413  | 
    ((\<^const_name>\<open>zero_class.zero\<close>, []), _) =>
  | 
| 
64962
 | 
   414  | 
      inst [] [n] @{thm diff_0_eq_0 [meta]}
 | 
| 
69597
 | 
   415  | 
  | (_, (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   416  | 
      inst [] [m] @{thm minus_nat.diff_0 [meta]}
 | 
| 
69597
 | 
   417  | 
  | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   418  | 
      transitive'
  | 
| 
 | 
   419  | 
        (inst [] [m, n] @{thm diff_nat_numeral [meta]})
 | 
| 
 | 
   420  | 
        (cong1' nat_conv (args2 int_minus_conv))
  | 
| 
 | 
   421  | 
  | _ => cong2'' nat_minus_conv (expand1_nat m) (expand1_nat n));
  | 
| 
64998
 | 
   422  | 
\<close>
  | 
| 
64962
 | 
   423  | 
  | 
| 
64998
 | 
   424  | 
ML \<open>
  | 
| 
64962
 | 
   425  | 
fun mult_num_conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   426  | 
    (_, (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   427  | 
      inst [] [m] @{thm mult_num_simps(1) [meta]}
 | 
| 
69597
 | 
   428  | 
  | ((\<^const_name>\<open>Num.One\<close>, []), _) =>
  | 
| 
64962
 | 
   429  | 
      inst [] [n] @{thm mult_num_simps(2) [meta]}
 | 
| 
69597
 | 
   430  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   431  | 
      transitive'
  | 
| 
 | 
   432  | 
        (inst [] [m, n] @{thm mult_num_simps(3) [meta]})
 | 
| 
 | 
   433  | 
        (cong1 (cong1 (args2 mult_num_conv)))
  | 
| 
69597
 | 
   434  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n'])) =>
  | 
| 
64962
 | 
   435  | 
      transitive'
  | 
| 
 | 
   436  | 
        (inst [] [m, n'] @{thm mult_num_simps(4) [meta]})
 | 
| 
 | 
   437  | 
        (cong1 (args2 mult_num_conv))
  | 
| 
69597
 | 
   438  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m']), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   439  | 
      transitive'
  | 
| 
 | 
   440  | 
        (inst [] [m', n] @{thm mult_num_simps(5) [meta]})
 | 
| 
 | 
   441  | 
        (cong1 (args2 mult_num_conv))
  | 
| 
69597
 | 
   442  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   443  | 
      transitive'
  | 
| 
 | 
   444  | 
        (inst [] [m, n] @{thm mult_num_simps(6) [meta]})
 | 
| 
 | 
   445  | 
        (cong1 (cong2' add_num_conv
  | 
| 
 | 
   446  | 
           (args2 add_num_conv)
  | 
| 
 | 
   447  | 
           (cong1 (args2 mult_num_conv)))));
  | 
| 
64998
 | 
   448  | 
\<close>
  | 
| 
64962
 | 
   449  | 
  | 
| 
64998
 | 
   450  | 
ML \<open>
  | 
| 
64962
 | 
   451  | 
fun mult_conv f a =
  | 
| 
 | 
   452  | 
  let
  | 
| 
 | 
   453  | 
    val mult_zero_left_a = inst [a] [] @{thm mult_zero_left [meta]};
 | 
| 
 | 
   454  | 
    val mult_zero_right_a = inst [a] [] @{thm mult_zero_right [meta]};
 | 
| 
 | 
   455  | 
    val numeral_times_numeral_a = inst [a] [] @{thm numeral_times_numeral [meta]};
 | 
| 
 | 
   456  | 
    val expand1_a = expand1 a;
  | 
| 
 | 
   457  | 
    val norm1_eq_a = norm1_eq a;
  | 
| 
 | 
   458  | 
  | 
| 
 | 
   459  | 
    fun conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   460  | 
        ((\<^const_name>\<open>zero_class.zero\<close>, []), _) => inst [] [n] mult_zero_left_a
  | 
| 
 | 
   461  | 
      | (_, (\<^const_name>\<open>zero_class.zero\<close>, [])) => inst [] [m] mult_zero_right_a
  | 
| 
 | 
   462  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   463  | 
          transitive'
  | 
| 
 | 
   464  | 
            (inst [] [m, n] numeral_times_numeral_a)
  | 
| 
 | 
   465  | 
            (cong1 (args2 mult_num_conv))
  | 
| 
 | 
   466  | 
      | _ => cong2'' (f conv) (expand1_a m) (expand1_a n))
  | 
| 
 | 
   467  | 
  in norm1_eq_a oo f conv end;
  | 
| 
 | 
   468  | 
  | 
| 
69597
 | 
   469  | 
val nat_mult_conv = mult_conv I \<^ctyp>\<open>nat\<close>;
  | 
| 
64998
 | 
   470  | 
\<close>
  | 
| 
64962
 | 
   471  | 
  | 
| 
64998
 | 
   472  | 
ML \<open>
  | 
| 
64962
 | 
   473  | 
fun mult_neg_conv a =
  | 
| 
 | 
   474  | 
  let
  | 
| 
 | 
   475  | 
    val [neg_numeral_times_neg_numeral_a, neg_numeral_times_numeral_a,
  | 
| 
 | 
   476  | 
         numeral_times_neg_numeral_a] =
  | 
| 
 | 
   477  | 
      map (inst [a] []) @{thms mult_neg_numeral_simps [meta]};
 | 
| 
 | 
   478  | 
  in
  | 
| 
 | 
   479  | 
    fn conv => fn m => fn n =>
  | 
| 
 | 
   480  | 
      case (strip_numeral m, strip_numeral n) of
  | 
| 
69597
 | 
   481  | 
        ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   482  | 
          transitive'
  | 
| 
 | 
   483  | 
            (inst [] [m, n] neg_numeral_times_neg_numeral_a)
  | 
| 
 | 
   484  | 
            (cong1 (args2 mult_num_conv))
  | 
| 
69597
 | 
   485  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   486  | 
          transitive'
  | 
| 
 | 
   487  | 
            (inst [] [m, n] neg_numeral_times_numeral_a)
  | 
| 
 | 
   488  | 
            (cong1 (cong1 (args2 mult_num_conv)))
  | 
| 
69597
 | 
   489  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   490  | 
          transitive'
  | 
| 
 | 
   491  | 
            (inst [] [m, n] numeral_times_neg_numeral_a)
  | 
| 
 | 
   492  | 
            (cong1 (cong1 (args2 mult_num_conv)))
  | 
| 
 | 
   493  | 
      | _ => conv m n
  | 
| 
 | 
   494  | 
  end;
  | 
| 
 | 
   495  | 
  | 
| 
 | 
   496  | 
fun mult_conv' a = mult_conv (mult_neg_conv a) a;
  | 
| 
 | 
   497  | 
  | 
| 
69597
 | 
   498  | 
val int_mult_conv = mult_conv' \<^ctyp>\<open>int\<close>;
  | 
| 
64998
 | 
   499  | 
\<close>
  | 
| 
64962
 | 
   500  | 
  | 
| 
64998
 | 
   501  | 
ML \<open>
  | 
| 
64962
 | 
   502  | 
fun eq_num_conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   503  | 
    ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   504  | 
      @{thm eq_num_simps(1) [meta]}
 | 
| 
69597
 | 
   505  | 
  | ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   506  | 
      inst [] [n] @{thm eq_num_simps(2) [meta]}
 | 
| 
69597
 | 
   507  | 
  | ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   508  | 
      inst [] [n] @{thm eq_num_simps(3) [meta]}
 | 
| 
69597
 | 
   509  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   510  | 
      inst [] [m] @{thm eq_num_simps(4) [meta]}
 | 
| 
69597
 | 
   511  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   512  | 
      inst [] [m] @{thm eq_num_simps(5) [meta]}
 | 
| 
69597
 | 
   513  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   514  | 
      Thm.transitive
  | 
| 
 | 
   515  | 
        (inst [] [m, n] @{thm eq_num_simps(6) [meta]})
 | 
| 
 | 
   516  | 
        (eq_num_conv m n)
  | 
| 
69597
 | 
   517  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   518  | 
      inst [] [m, n] @{thm eq_num_simps(7) [meta]}
 | 
| 
69597
 | 
   519  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   520  | 
      inst [] [m, n] @{thm eq_num_simps(8) [meta]}
 | 
| 
69597
 | 
   521  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   522  | 
      Thm.transitive
  | 
| 
 | 
   523  | 
        (inst [] [m, n] @{thm eq_num_simps(9) [meta]})
 | 
| 
 | 
   524  | 
        (eq_num_conv m n));
  | 
| 
64998
 | 
   525  | 
\<close>
  | 
| 
64962
 | 
   526  | 
  | 
| 
64998
 | 
   527  | 
ML \<open>
  | 
| 
64962
 | 
   528  | 
fun eq_conv f a =
  | 
| 
 | 
   529  | 
  let
  | 
| 
 | 
   530  | 
    val zero_eq_zero_a = inst [a] [] @{thm refl [of 0, THEN Eq_TrueI]};
 | 
| 
 | 
   531  | 
    val zero_neq_numeral_a =
  | 
| 
 | 
   532  | 
      inst [a] [] @{thm zero_neq_numeral [THEN Eq_FalseI]};
 | 
| 
 | 
   533  | 
    val numeral_neq_zero_a =
  | 
| 
 | 
   534  | 
      inst [a] [] @{thm numeral_neq_zero [THEN Eq_FalseI]};
 | 
| 
 | 
   535  | 
    val numeral_eq_iff_a = inst [a] [] @{thm numeral_eq_iff [meta]};
 | 
| 
 | 
   536  | 
    val expand1_a = expand1 a;
  | 
| 
 | 
   537  | 
  | 
| 
 | 
   538  | 
    fun conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   539  | 
        ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   540  | 
          zero_eq_zero_a
  | 
| 
69597
 | 
   541  | 
      | ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   542  | 
          inst [] [n] zero_neq_numeral_a
  | 
| 
69597
 | 
   543  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   544  | 
          inst [] [m] numeral_neq_zero_a
  | 
| 
69597
 | 
   545  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   546  | 
          Thm.transitive
  | 
| 
 | 
   547  | 
            (inst [] [m, n] numeral_eq_iff_a)
  | 
| 
 | 
   548  | 
            (eq_num_conv m n)
  | 
| 
 | 
   549  | 
      | _ => cong2'' (f conv) (expand1_a m) (expand1_a n))
  | 
| 
 | 
   550  | 
  in f conv end;
  | 
| 
 | 
   551  | 
  | 
| 
69597
 | 
   552  | 
val nat_eq_conv = eq_conv I \<^ctyp>\<open>nat\<close>;
  | 
| 
64998
 | 
   553  | 
\<close>
  | 
| 
64962
 | 
   554  | 
  | 
| 
64998
 | 
   555  | 
ML \<open>
  | 
| 
64962
 | 
   556  | 
fun eq_neg_conv a =
  | 
| 
 | 
   557  | 
  let
  | 
| 
 | 
   558  | 
    val neg_numeral_neq_zero_a =
  | 
| 
 | 
   559  | 
      inst [a] [] @{thm neg_numeral_neq_zero [THEN Eq_FalseI]};
 | 
| 
 | 
   560  | 
    val zero_neq_neg_numeral_a =
  | 
| 
 | 
   561  | 
      inst [a] [] @{thm zero_neq_neg_numeral [THEN Eq_FalseI]};
 | 
| 
 | 
   562  | 
    val neg_numeral_neq_numeral_a =
  | 
| 
 | 
   563  | 
      inst [a] [] @{thm neg_numeral_neq_numeral [THEN Eq_FalseI]};
 | 
| 
 | 
   564  | 
    val numeral_neq_neg_numeral_a =
  | 
| 
 | 
   565  | 
      inst [a] [] @{thm numeral_neq_neg_numeral [THEN Eq_FalseI]};
 | 
| 
 | 
   566  | 
    val neg_numeral_eq_iff_a = inst [a] [] @{thm neg_numeral_eq_iff [meta]}
 | 
| 
 | 
   567  | 
  in
  | 
| 
 | 
   568  | 
    fn conv => fn m => fn n => 
  | 
| 
 | 
   569  | 
      case (strip_numeral m, strip_numeral n) of
  | 
| 
69597
 | 
   570  | 
        ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   571  | 
          inst [] [m] neg_numeral_neq_zero_a
  | 
| 
69597
 | 
   572  | 
      | ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   573  | 
          inst [] [n] zero_neq_neg_numeral_a
  | 
| 
69597
 | 
   574  | 
      | ((\<^const_name>\<open>Num.numeral\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   575  | 
          inst [] [m, n] numeral_neq_neg_numeral_a
  | 
| 
69597
 | 
   576  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>Num.numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   577  | 
          inst [] [m, n] neg_numeral_neq_numeral_a
  | 
| 
69597
 | 
   578  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   579  | 
          Thm.transitive
  | 
| 
 | 
   580  | 
            (inst [] [m, n] neg_numeral_eq_iff_a)
  | 
| 
 | 
   581  | 
            (eq_num_conv m n)
  | 
| 
 | 
   582  | 
      | _ => conv m n
  | 
| 
 | 
   583  | 
  end;
  | 
| 
 | 
   584  | 
  | 
| 
 | 
   585  | 
fun eq_conv' a = eq_conv (eq_neg_conv a) a;
  | 
| 
 | 
   586  | 
  | 
| 
69597
 | 
   587  | 
val int_eq_conv = eq_conv' \<^ctyp>\<open>int\<close>;
  | 
| 
64998
 | 
   588  | 
\<close>
  | 
| 
64962
 | 
   589  | 
  | 
| 
64998
 | 
   590  | 
ML \<open>
  | 
| 
64962
 | 
   591  | 
fun le_num_conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   592  | 
    ((\<^const_name>\<open>Num.One\<close>, []), _) =>
  | 
| 
64962
 | 
   593  | 
      inst [] [n] @{thm le_num_simps(1) [meta]}
 | 
| 
69597
 | 
   594  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   595  | 
      inst [] [m] @{thm le_num_simps(2) [meta]}
 | 
| 
69597
 | 
   596  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   597  | 
      inst [] [m] @{thm le_num_simps(3) [meta]}
 | 
| 
69597
 | 
   598  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   599  | 
      Thm.transitive
  | 
| 
 | 
   600  | 
        (inst [] [m, n] @{thm le_num_simps(4) [meta]})
 | 
| 
 | 
   601  | 
        (le_num_conv m n)
  | 
| 
69597
 | 
   602  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   603  | 
      Thm.transitive
  | 
| 
 | 
   604  | 
        (inst [] [m, n] @{thm le_num_simps(5) [meta]})
 | 
| 
 | 
   605  | 
        (le_num_conv m n)
  | 
| 
69597
 | 
   606  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   607  | 
      Thm.transitive
  | 
| 
 | 
   608  | 
        (inst [] [m, n] @{thm le_num_simps(6) [meta]})
 | 
| 
 | 
   609  | 
        (le_num_conv m n)
  | 
| 
69597
 | 
   610  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   611  | 
      Thm.transitive
  | 
| 
 | 
   612  | 
        (inst [] [m, n] @{thm le_num_simps(7) [meta]})
 | 
| 
 | 
   613  | 
        (less_num_conv m n))
  | 
| 
 | 
   614  | 
  | 
| 
 | 
   615  | 
and less_num_conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   616  | 
    (_, (\<^const_name>\<open>Num.One\<close>, [])) =>
  | 
| 
64962
 | 
   617  | 
      inst [] [m] @{thm less_num_simps(1) [meta]}
 | 
| 
69597
 | 
   618  | 
  | ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   619  | 
      inst [] [n] @{thm less_num_simps(2) [meta]}
 | 
| 
69597
 | 
   620  | 
  | ((\<^const_name>\<open>Num.One\<close>, []), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   621  | 
      inst [] [n] @{thm less_num_simps(3) [meta]}
 | 
| 
69597
 | 
   622  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   623  | 
      Thm.transitive
  | 
| 
 | 
   624  | 
        (inst [] [m, n] @{thm less_num_simps(4) [meta]})
 | 
| 
 | 
   625  | 
        (less_num_conv m n)
  | 
| 
69597
 | 
   626  | 
  | ((\<^const_name>\<open>Num.Bit0\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   627  | 
      Thm.transitive
  | 
| 
 | 
   628  | 
        (inst [] [m, n] @{thm less_num_simps(5) [meta]})
 | 
| 
 | 
   629  | 
        (le_num_conv m n)
  | 
| 
69597
 | 
   630  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit1\<close>, [n])) =>
  | 
| 
64962
 | 
   631  | 
      Thm.transitive
  | 
| 
 | 
   632  | 
        (inst [] [m, n] @{thm less_num_simps(6) [meta]})
 | 
| 
 | 
   633  | 
        (less_num_conv m n)
  | 
| 
69597
 | 
   634  | 
  | ((\<^const_name>\<open>Num.Bit1\<close>, [m]), (\<^const_name>\<open>Num.Bit0\<close>, [n])) =>
  | 
| 
64962
 | 
   635  | 
      Thm.transitive
  | 
| 
 | 
   636  | 
        (inst [] [m, n] @{thm less_num_simps(7) [meta]})
 | 
| 
 | 
   637  | 
        (less_num_conv m n));
  | 
| 
64998
 | 
   638  | 
\<close>
  | 
| 
64962
 | 
   639  | 
  | 
| 
64998
 | 
   640  | 
ML \<open>
  | 
| 
64962
 | 
   641  | 
fun le_conv f a =
  | 
| 
 | 
   642  | 
  let
  | 
| 
 | 
   643  | 
    val zero_le_zero_a = inst [a] [] @{thm order_refl [of 0, THEN Eq_TrueI]};
 | 
| 
 | 
   644  | 
    val zero_le_numeral_a =
  | 
| 
 | 
   645  | 
      inst [a] [] @{thm zero_le_numeral [THEN Eq_TrueI]};
 | 
| 
 | 
   646  | 
    val not_numeral_le_zero_a =
  | 
| 
 | 
   647  | 
      inst [a] [] @{thm not_numeral_le_zero [THEN Eq_FalseI]};
 | 
| 
 | 
   648  | 
    val numeral_le_iff_a = inst [a] [] @{thm numeral_le_iff [meta]};
 | 
| 
 | 
   649  | 
    val expand1_a = expand1 a;
  | 
| 
 | 
   650  | 
  | 
| 
 | 
   651  | 
    fun conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   652  | 
        ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   653  | 
          zero_le_zero_a
  | 
| 
69597
 | 
   654  | 
      | ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   655  | 
          inst [] [n] zero_le_numeral_a
  | 
| 
69597
 | 
   656  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   657  | 
          inst [] [m] not_numeral_le_zero_a
  | 
| 
69597
 | 
   658  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   659  | 
          Thm.transitive
  | 
| 
 | 
   660  | 
            (inst [] [m, n] numeral_le_iff_a)
  | 
| 
 | 
   661  | 
            (le_num_conv m n)
  | 
| 
 | 
   662  | 
      | _ => cong2'' (f conv) (expand1_a m) (expand1_a n))
  | 
| 
 | 
   663  | 
  in f conv end;
  | 
| 
 | 
   664  | 
  | 
| 
69597
 | 
   665  | 
val nat_le_conv = le_conv I \<^ctyp>\<open>nat\<close>;
  | 
| 
64998
 | 
   666  | 
\<close>
  | 
| 
64962
 | 
   667  | 
  | 
| 
64998
 | 
   668  | 
ML \<open>
  | 
| 
64962
 | 
   669  | 
fun le_neg_conv a =
  | 
| 
 | 
   670  | 
  let
  | 
| 
 | 
   671  | 
    val neg_numeral_le_zero_a =
  | 
| 
 | 
   672  | 
      inst [a] [] @{thm neg_numeral_le_zero [THEN Eq_TrueI]};
 | 
| 
 | 
   673  | 
    val not_zero_le_neg_numeral_a =
  | 
| 
 | 
   674  | 
      inst [a] [] @{thm not_zero_le_neg_numeral [THEN Eq_FalseI]};
 | 
| 
 | 
   675  | 
    val neg_numeral_le_numeral_a =
  | 
| 
 | 
   676  | 
      inst [a] [] @{thm neg_numeral_le_numeral [THEN Eq_TrueI]};
 | 
| 
 | 
   677  | 
    val not_numeral_le_neg_numeral_a =
  | 
| 
 | 
   678  | 
      inst [a] [] @{thm not_numeral_le_neg_numeral [THEN Eq_FalseI]};
 | 
| 
 | 
   679  | 
    val neg_numeral_le_iff_a = inst [a] [] @{thm neg_numeral_le_iff [meta]}
 | 
| 
 | 
   680  | 
  in
  | 
| 
 | 
   681  | 
    fn conv => fn m => fn n => 
  | 
| 
 | 
   682  | 
      case (strip_numeral m, strip_numeral n) of
  | 
| 
69597
 | 
   683  | 
        ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   684  | 
          inst [] [m] neg_numeral_le_zero_a
  | 
| 
69597
 | 
   685  | 
      | ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   686  | 
          inst [] [n] not_zero_le_neg_numeral_a
  | 
| 
69597
 | 
   687  | 
      | ((\<^const_name>\<open>Num.numeral\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   688  | 
          inst [] [m, n] not_numeral_le_neg_numeral_a
  | 
| 
69597
 | 
   689  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>Num.numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   690  | 
          inst [] [m, n] neg_numeral_le_numeral_a
  | 
| 
69597
 | 
   691  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   692  | 
          Thm.transitive
  | 
| 
 | 
   693  | 
            (inst [] [m, n] neg_numeral_le_iff_a)
  | 
| 
 | 
   694  | 
            (le_num_conv n m)
  | 
| 
 | 
   695  | 
      | _ => conv m n
  | 
| 
 | 
   696  | 
  end;
  | 
| 
 | 
   697  | 
  | 
| 
 | 
   698  | 
fun le_conv' a = le_conv (le_neg_conv a) a;
  | 
| 
 | 
   699  | 
  | 
| 
69597
 | 
   700  | 
val int_le_conv = le_conv' \<^ctyp>\<open>int\<close>;
  | 
| 
64998
 | 
   701  | 
\<close>
  | 
| 
64962
 | 
   702  | 
  | 
| 
64998
 | 
   703  | 
ML \<open>
  | 
| 
64962
 | 
   704  | 
fun less_conv f a =
  | 
| 
 | 
   705  | 
  let
  | 
| 
 | 
   706  | 
    val not_zero_less_zero_a = inst [a] [] @{thm less_irrefl [of 0, THEN Eq_FalseI]};
 | 
| 
 | 
   707  | 
    val zero_less_numeral_a =
  | 
| 
 | 
   708  | 
      inst [a] [] @{thm zero_less_numeral [THEN Eq_TrueI]};
 | 
| 
 | 
   709  | 
    val not_numeral_less_zero_a =
  | 
| 
 | 
   710  | 
      inst [a] [] @{thm not_numeral_less_zero [THEN Eq_FalseI]};
 | 
| 
 | 
   711  | 
    val numeral_less_iff_a = inst [a] [] @{thm numeral_less_iff [meta]};
 | 
| 
 | 
   712  | 
    val expand1_a = expand1 a;
  | 
| 
 | 
   713  | 
  | 
| 
 | 
   714  | 
    fun conv m n = (case (strip_app m, strip_app n) of
  | 
| 
69597
 | 
   715  | 
        ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   716  | 
          not_zero_less_zero_a
  | 
| 
69597
 | 
   717  | 
      | ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   718  | 
          inst [] [n] zero_less_numeral_a
  | 
| 
69597
 | 
   719  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   720  | 
          inst [] [m] not_numeral_less_zero_a
  | 
| 
69597
 | 
   721  | 
      | ((\<^const_name>\<open>numeral\<close>, [m]), (\<^const_name>\<open>numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   722  | 
          Thm.transitive
  | 
| 
 | 
   723  | 
            (inst [] [m, n] numeral_less_iff_a)
  | 
| 
 | 
   724  | 
            (less_num_conv m n)
  | 
| 
 | 
   725  | 
      | _ => cong2'' (f conv) (expand1_a m) (expand1_a n))
  | 
| 
 | 
   726  | 
  in f conv end;
  | 
| 
 | 
   727  | 
  | 
| 
69597
 | 
   728  | 
val nat_less_conv = less_conv I \<^ctyp>\<open>nat\<close>;
  | 
| 
64998
 | 
   729  | 
\<close>
  | 
| 
64962
 | 
   730  | 
  | 
| 
64998
 | 
   731  | 
ML \<open>
  | 
| 
64962
 | 
   732  | 
fun less_neg_conv a =
  | 
| 
 | 
   733  | 
  let
  | 
| 
 | 
   734  | 
    val neg_numeral_less_zero_a =
  | 
| 
 | 
   735  | 
      inst [a] [] @{thm neg_numeral_less_zero [THEN Eq_TrueI]};
 | 
| 
 | 
   736  | 
    val not_zero_less_neg_numeral_a =
  | 
| 
 | 
   737  | 
      inst [a] [] @{thm not_zero_less_neg_numeral [THEN Eq_FalseI]};
 | 
| 
 | 
   738  | 
    val neg_numeral_less_numeral_a =
  | 
| 
 | 
   739  | 
      inst [a] [] @{thm neg_numeral_less_numeral [THEN Eq_TrueI]};
 | 
| 
 | 
   740  | 
    val not_numeral_less_neg_numeral_a =
  | 
| 
 | 
   741  | 
      inst [a] [] @{thm not_numeral_less_neg_numeral [THEN Eq_FalseI]};
 | 
| 
 | 
   742  | 
    val neg_numeral_less_iff_a = inst [a] [] @{thm neg_numeral_less_iff [meta]}
 | 
| 
 | 
   743  | 
  in
  | 
| 
 | 
   744  | 
    fn conv => fn m => fn n => 
  | 
| 
 | 
   745  | 
      case (strip_numeral m, strip_numeral n) of
  | 
| 
69597
 | 
   746  | 
        ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>zero_class.zero\<close>, [])) =>
  | 
| 
64962
 | 
   747  | 
          inst [] [m] neg_numeral_less_zero_a
  | 
| 
69597
 | 
   748  | 
      | ((\<^const_name>\<open>zero_class.zero\<close>, []), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   749  | 
          inst [] [n] not_zero_less_neg_numeral_a
  | 
| 
69597
 | 
   750  | 
      | ((\<^const_name>\<open>Num.numeral\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   751  | 
          inst [] [m, n] not_numeral_less_neg_numeral_a
  | 
| 
69597
 | 
   752  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>Num.numeral\<close>, [n])) =>
  | 
| 
64962
 | 
   753  | 
          inst [] [m, n] neg_numeral_less_numeral_a
  | 
| 
69597
 | 
   754  | 
      | ((\<^const_name>\<open>uminus\<close>, [m]), (\<^const_name>\<open>uminus\<close>, [n])) =>
  | 
| 
64962
 | 
   755  | 
          Thm.transitive
  | 
| 
 | 
   756  | 
            (inst [] [m, n] neg_numeral_less_iff_a)
  | 
| 
 | 
   757  | 
            (less_num_conv n m)
  | 
| 
 | 
   758  | 
      | _ => conv m n
  | 
| 
 | 
   759  | 
  end;
  | 
| 
 | 
   760  | 
  | 
| 
 | 
   761  | 
fun less_conv' a = less_conv (less_neg_conv a) a;
  | 
| 
 | 
   762  | 
  | 
| 
69597
 | 
   763  | 
val int_less_conv = less_conv' \<^ctyp>\<open>int\<close>;
  | 
| 
64998
 | 
   764  | 
\<close>
  | 
| 
64962
 | 
   765  | 
  | 
| 
64998
 | 
   766  | 
ML \<open>
  | 
| 
64962
 | 
   767  | 
fun If_conv a =
  | 
| 
 | 
   768  | 
  let
  | 
| 
 | 
   769  | 
    val if_True = inst [a] [] @{thm if_True [meta]};
 | 
| 
 | 
   770  | 
    val if_False = inst [a] [] @{thm if_False [meta]}
 | 
| 
 | 
   771  | 
  in
  | 
| 
 | 
   772  | 
    fn p => fn x => fn y => fn ct =>
  | 
| 
 | 
   773  | 
      case strip_app ct of
  | 
| 
69597
 | 
   774  | 
        (\<^const_name>\<open>If\<close>, [cb, cx, cy]) =>
  | 
| 
64962
 | 
   775  | 
          let
  | 
| 
 | 
   776  | 
            val p_eq = p cb
  | 
| 
 | 
   777  | 
            val eq = Thm.combination (Thm.reflexive (Thm.dest_fun (Thm.dest_fun2 ct))) p_eq
  | 
| 
 | 
   778  | 
          in
  | 
| 
 | 
   779  | 
            case Thm.term_of (Thm.rhs_of p_eq) of
  | 
| 
69597
 | 
   780  | 
              Const (\<^const_name>\<open>True\<close>, _) =>
  | 
| 
64962
 | 
   781  | 
                let
  | 
| 
 | 
   782  | 
                  val x_eq = x cx;
  | 
| 
 | 
   783  | 
                  val cx = Thm.rhs_of x_eq;
  | 
| 
 | 
   784  | 
                in
  | 
| 
 | 
   785  | 
                  Thm.transitive
  | 
| 
 | 
   786  | 
                    (Thm.combination
  | 
| 
 | 
   787  | 
                       (Thm.combination eq x_eq)
  | 
| 
 | 
   788  | 
                       (Thm.reflexive cy))
  | 
| 
 | 
   789  | 
                    (inst [] [cx, cy] if_True)
  | 
| 
 | 
   790  | 
                end
  | 
| 
69597
 | 
   791  | 
            | Const (\<^const_name>\<open>False\<close>, _) =>
  | 
| 
64962
 | 
   792  | 
                let
  | 
| 
 | 
   793  | 
                  val y_eq = y cy;
  | 
| 
 | 
   794  | 
                  val cy = Thm.rhs_of y_eq;
  | 
| 
 | 
   795  | 
                in
  | 
| 
 | 
   796  | 
                  Thm.transitive
  | 
| 
 | 
   797  | 
                    (Thm.combination
  | 
| 
 | 
   798  | 
                       (Thm.combination eq (Thm.reflexive cx))
  | 
| 
 | 
   799  | 
                       y_eq)
  | 
| 
 | 
   800  | 
                    (inst [] [cx, cy] if_False)
  | 
| 
 | 
   801  | 
                end
  | 
| 
 | 
   802  | 
            | _ => err "If_conv" (Thm.rhs_of p_eq)
  | 
| 
 | 
   803  | 
          end
  | 
| 
 | 
   804  | 
  end;
  | 
| 
64998
 | 
   805  | 
\<close>
  | 
| 
64962
 | 
   806  | 
  | 
| 
64998
 | 
   807  | 
ML \<open>
  | 
| 
64962
 | 
   808  | 
fun drop_conv a =
  | 
| 
 | 
   809  | 
  let
  | 
| 
 | 
   810  | 
    val drop_0_a = inst [a] [] @{thm drop_0 [meta]};
 | 
| 
 | 
   811  | 
    val drop_Cons_a = inst [a] [] @{thm drop_Cons' [meta]};
 | 
| 
 | 
   812  | 
    val If_conv_a = If_conv (type_of_eqn drop_0_a);
  | 
| 
 | 
   813  | 
  | 
| 
 | 
   814  | 
    fun conv n ys = (case Thm.term_of n of
  | 
| 
69597
 | 
   815  | 
        Const (\<^const_name>\<open>zero_class.zero\<close>, _) => inst [] [ys] drop_0_a
  | 
| 
64962
 | 
   816  | 
      | _ => (case strip_app ys of
  | 
| 
69597
 | 
   817  | 
          (\<^const_name>\<open>Cons\<close>, [x, xs]) =>
  | 
| 
64962
 | 
   818  | 
            transitive'
  | 
| 
 | 
   819  | 
              (inst [] [n, x, xs] drop_Cons_a)
  | 
| 
 | 
   820  | 
              (If_conv_a (args2 nat_eq_conv)
  | 
| 
 | 
   821  | 
                 Thm.reflexive
  | 
| 
 | 
   822  | 
                 (cong2' conv (args2 nat_minus_conv) Thm.reflexive))))
  | 
| 
 | 
   823  | 
  in conv end;
  | 
| 
64998
 | 
   824  | 
\<close>
  | 
| 
64962
 | 
   825  | 
  | 
| 
64998
 | 
   826  | 
ML \<open>
  | 
| 
64962
 | 
   827  | 
fun nth_conv a =
  | 
| 
 | 
   828  | 
  let
  | 
| 
 | 
   829  | 
    val nth_Cons_a = inst [a] [] @{thm nth_Cons' [meta]};
 | 
| 
 | 
   830  | 
    val If_conv_a = If_conv a;
  | 
| 
 | 
   831  | 
  | 
| 
 | 
   832  | 
    fun conv ys n = (case strip_app ys of
  | 
| 
69597
 | 
   833  | 
        (\<^const_name>\<open>Cons\<close>, [x, xs]) =>
  | 
| 
64962
 | 
   834  | 
          transitive'
  | 
| 
 | 
   835  | 
            (inst [] [x, xs, n] nth_Cons_a)
  | 
| 
 | 
   836  | 
            (If_conv_a (args2 nat_eq_conv)
  | 
| 
 | 
   837  | 
               Thm.reflexive
  | 
| 
 | 
   838  | 
               (cong2' conv Thm.reflexive (args2 nat_minus_conv))))
  | 
| 
 | 
   839  | 
  in conv end;
  | 
| 
64998
 | 
   840  | 
\<close>
  | 
| 
64962
 | 
   841  | 
  | 
| 
 | 
   842  | 
end
  |