src/HOL/Decision_Procs/Commutative_Ring.thy
author wenzelm
Thu, 08 Nov 2018 15:49:56 +0100
changeset 69266 7cc2d66a92a6
parent 67649 1e1782c1aedf
child 69597 ff784d5a5bfb
permissions -rw-r--r--
proper ML expressions, without trailing semicolons;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
     1
(*  Title:      HOL/Decision_Procs/Commutative_Ring.thy
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
     2
    Author:     Bernhard Haeupler, Stefan Berghofer, and Amine Chaieb
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
     3
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
     4
Proving equalities in commutative rings done "right" in Isabelle/HOL.
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
     5
*)
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
     6
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
     7
section \<open>Proving equalities in commutative rings\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
     8
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
     9
theory Commutative_Ring
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    10
  imports
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    11
    Conversions
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    12
    Algebra_Aux
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    13
    "HOL-Library.Code_Target_Numeral"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    14
begin
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    15
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    16
text \<open>Syntax of multivariate polynomials (pol) and polynomial expressions.\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    17
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    18
datatype pol =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    19
    Pc int
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    20
  | Pinj nat pol
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    21
  | PX pol nat pol
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    22
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    23
datatype polex =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    24
    Var nat
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    25
  | Const int
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    26
  | Add polex polex
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    27
  | Sub polex polex
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    28
  | Mul polex polex
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    29
  | Pow polex nat
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    30
  | Neg polex
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    31
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    32
text \<open>Interpretation functions for the shadow syntax.\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    33
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    34
context cring
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    35
begin
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    36
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    37
definition in_carrier :: "'a list \<Rightarrow> bool"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    38
  where "in_carrier xs \<longleftrightarrow> (\<forall>x\<in>set xs. x \<in> carrier R)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    39
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    40
lemma in_carrier_Nil: "in_carrier []"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    41
  by (simp add: in_carrier_def)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    42
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    43
lemma in_carrier_Cons: "x \<in> carrier R \<Longrightarrow> in_carrier xs \<Longrightarrow> in_carrier (x # xs)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    44
  by (simp add: in_carrier_def)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    45
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    46
lemma drop_in_carrier [simp]: "in_carrier xs \<Longrightarrow> in_carrier (drop n xs)"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    47
  using set_drop_subset [of n xs] by (auto simp add: in_carrier_def)
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    48
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    49
primrec head :: "'a list \<Rightarrow> 'a"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    50
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    51
    "head [] = \<zero>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    52
  | "head (x # xs) = x"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    53
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    54
lemma head_closed [simp]: "in_carrier xs \<Longrightarrow> head xs \<in> carrier R"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    55
  by (cases xs) (simp_all add: in_carrier_def)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    56
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    57
primrec Ipol :: "'a list \<Rightarrow> pol \<Rightarrow> 'a"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    58
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    59
    "Ipol l (Pc c) = \<guillemotleft>c\<guillemotright>"
22742
06165e40e7bd switched from recdef to function package; constants add, mul, pow now curried; infix syntax for algebraic operations.
haftmann
parents: 22665
diff changeset
    60
  | "Ipol l (Pinj i P) = Ipol (drop i l) P"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
    61
  | "Ipol l (PX P x Q) = Ipol l P \<otimes> head l [^] x \<oplus> Ipol (drop 1 l) Q"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    62
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    63
lemma Ipol_Pc:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    64
  "Ipol l (Pc 0) = \<zero>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    65
  "Ipol l (Pc 1) = \<one>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    66
  "Ipol l (Pc (numeral n)) = \<guillemotleft>numeral n\<guillemotright>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    67
  "Ipol l (Pc (- numeral n)) = \<ominus> \<guillemotleft>numeral n\<guillemotright>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    68
  by simp_all
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    69
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    70
lemma Ipol_closed [simp]: "in_carrier l \<Longrightarrow> Ipol l p \<in> carrier R"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    71
  by (induct p arbitrary: l) simp_all
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    72
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    73
primrec Ipolex :: "'a list \<Rightarrow> polex \<Rightarrow> 'a"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    74
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    75
    "Ipolex l (Var n) = head (drop n l)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    76
  | "Ipolex l (Const i) = \<guillemotleft>i\<guillemotright>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    77
  | "Ipolex l (Add P Q) = Ipolex l P \<oplus> Ipolex l Q"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    78
  | "Ipolex l (Sub P Q) = Ipolex l P \<ominus> Ipolex l Q"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    79
  | "Ipolex l (Mul P Q) = Ipolex l P \<otimes> Ipolex l Q"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
    80
  | "Ipolex l (Pow p n) = Ipolex l p [^] n"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    81
  | "Ipolex l (Neg P) = \<ominus> Ipolex l P"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    82
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    83
lemma Ipolex_Const:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    84
  "Ipolex l (Const 0) = \<zero>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    85
  "Ipolex l (Const 1) = \<one>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    86
  "Ipolex l (Const (numeral n)) = \<guillemotleft>numeral n\<guillemotright>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    87
  by simp_all
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    88
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    89
end
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    90
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
    91
text \<open>Create polynomial normalized polynomials given normalized inputs.\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    92
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
    93
definition mkPinj :: "nat \<Rightarrow> pol \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
    94
  where "mkPinj x P =
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
    95
    (case P of
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
    96
      Pc c \<Rightarrow> Pc c
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
    97
    | Pinj y P \<Rightarrow> Pinj (x + y) P
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
    98
    | PX p1 y p2 \<Rightarrow> Pinj x P)"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
    99
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   100
definition mkPX :: "pol \<Rightarrow> nat \<Rightarrow> pol \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   101
  where "mkPX P i Q =
55754
d14072d53c1e tuned specifications and proofs;
wenzelm
parents: 53077
diff changeset
   102
    (case P of
d14072d53c1e tuned specifications and proofs;
wenzelm
parents: 53077
diff changeset
   103
      Pc c \<Rightarrow> if c = 0 then mkPinj 1 Q else PX P i Q
d14072d53c1e tuned specifications and proofs;
wenzelm
parents: 53077
diff changeset
   104
    | Pinj j R \<Rightarrow> PX P i Q
d14072d53c1e tuned specifications and proofs;
wenzelm
parents: 53077
diff changeset
   105
    | PX P2 i2 Q2 \<Rightarrow> if Q2 = Pc 0 then PX P2 (i + i2) Q else PX P i Q)"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   106
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   107
text \<open>Defining the basic ring operations on normalized polynomials\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   108
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   109
function add :: "pol \<Rightarrow> pol \<Rightarrow> pol"  (infixl "\<langle>+\<rangle>" 65)
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   110
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   111
    "Pc a \<langle>+\<rangle> Pc b = Pc (a + b)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   112
  | "Pc c \<langle>+\<rangle> Pinj i P = Pinj i (P \<langle>+\<rangle> Pc c)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   113
  | "Pinj i P \<langle>+\<rangle> Pc c = Pinj i (P \<langle>+\<rangle> Pc c)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   114
  | "Pc c \<langle>+\<rangle> PX P i Q = PX P i (Q \<langle>+\<rangle> Pc c)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   115
  | "PX P i Q \<langle>+\<rangle> Pc c = PX P i (Q \<langle>+\<rangle> Pc c)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   116
  | "Pinj x P \<langle>+\<rangle> Pinj y Q =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   117
      (if x = y then mkPinj x (P \<langle>+\<rangle> Q)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   118
       else (if x > y then mkPinj y (Pinj (x - y) P \<langle>+\<rangle> Q)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   119
         else mkPinj x (Pinj (y - x) Q \<langle>+\<rangle> P)))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   120
  | "Pinj x P \<langle>+\<rangle> PX Q y R =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   121
      (if x = 0 then P \<langle>+\<rangle> PX Q y R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   122
       else (if x = 1 then PX Q y (R \<langle>+\<rangle> P)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   123
         else PX Q y (R \<langle>+\<rangle> Pinj (x - 1) P)))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   124
  | "PX P x R \<langle>+\<rangle> Pinj y Q =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   125
      (if y = 0 then PX P x R \<langle>+\<rangle> Q
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   126
       else (if y = 1 then PX P x (R \<langle>+\<rangle> Q)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   127
         else PX P x (R \<langle>+\<rangle> Pinj (y - 1) Q)))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   128
  | "PX P1 x P2 \<langle>+\<rangle> PX Q1 y Q2 =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   129
      (if x = y then mkPX (P1 \<langle>+\<rangle> Q1) x (P2 \<langle>+\<rangle> Q2)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   130
       else (if x > y then mkPX (PX P1 (x - y) (Pc 0) \<langle>+\<rangle> Q1) y (P2 \<langle>+\<rangle> Q2)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   131
         else mkPX (PX Q1 (y - x) (Pc 0) \<langle>+\<rangle> P1) x (P2 \<langle>+\<rangle> Q2)))"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   132
  by pat_completeness auto
22742
06165e40e7bd switched from recdef to function package; constants add, mul, pow now curried; infix syntax for algebraic operations.
haftmann
parents: 22665
diff changeset
   133
termination by (relation "measure (\<lambda>(x, y). size x + size y)") auto
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   134
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   135
function mul :: "pol \<Rightarrow> pol \<Rightarrow> pol"  (infixl "\<langle>*\<rangle>" 70)
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   136
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   137
    "Pc a \<langle>*\<rangle> Pc b = Pc (a * b)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   138
  | "Pc c \<langle>*\<rangle> Pinj i P =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   139
      (if c = 0 then Pc 0 else mkPinj i (P \<langle>*\<rangle> Pc c))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   140
  | "Pinj i P \<langle>*\<rangle> Pc c =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   141
      (if c = 0 then Pc 0 else mkPinj i (P \<langle>*\<rangle> Pc c))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   142
  | "Pc c \<langle>*\<rangle> PX P i Q =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   143
      (if c = 0 then Pc 0 else mkPX (P \<langle>*\<rangle> Pc c) i (Q \<langle>*\<rangle> Pc c))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   144
  | "PX P i Q \<langle>*\<rangle> Pc c =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   145
      (if c = 0 then Pc 0 else mkPX (P \<langle>*\<rangle> Pc c) i (Q \<langle>*\<rangle> Pc c))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   146
  | "Pinj x P \<langle>*\<rangle> Pinj y Q =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   147
      (if x = y then mkPinj x (P \<langle>*\<rangle> Q)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   148
       else
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   149
         (if x > y then mkPinj y (Pinj (x - y) P \<langle>*\<rangle> Q)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   150
          else mkPinj x (Pinj (y - x) Q \<langle>*\<rangle> P)))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   151
  | "Pinj x P \<langle>*\<rangle> PX Q y R =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   152
      (if x = 0 then P \<langle>*\<rangle> PX Q y R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   153
       else
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   154
         (if x = 1 then mkPX (Pinj x P \<langle>*\<rangle> Q) y (R \<langle>*\<rangle> P)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   155
          else mkPX (Pinj x P \<langle>*\<rangle> Q) y (R \<langle>*\<rangle> Pinj (x - 1) P)))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   156
  | "PX P x R \<langle>*\<rangle> Pinj y Q =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   157
      (if y = 0 then PX P x R \<langle>*\<rangle> Q
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   158
       else
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   159
         (if y = 1 then mkPX (Pinj y Q \<langle>*\<rangle> P) x (R \<langle>*\<rangle> Q)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   160
          else mkPX (Pinj y Q \<langle>*\<rangle> P) x (R \<langle>*\<rangle> Pinj (y - 1) Q)))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   161
  | "PX P1 x P2 \<langle>*\<rangle> PX Q1 y Q2 =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   162
      mkPX (P1 \<langle>*\<rangle> Q1) (x + y) (P2 \<langle>*\<rangle> Q2) \<langle>+\<rangle>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   163
        (mkPX (P1 \<langle>*\<rangle> mkPinj 1 Q2) x (Pc 0) \<langle>+\<rangle>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   164
          (mkPX (Q1 \<langle>*\<rangle> mkPinj 1 P2) y (Pc 0)))"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   165
  by pat_completeness auto
22742
06165e40e7bd switched from recdef to function package; constants add, mul, pow now curried; infix syntax for algebraic operations.
haftmann
parents: 22665
diff changeset
   166
termination by (relation "measure (\<lambda>(x, y). size x + size y)")
06165e40e7bd switched from recdef to function package; constants add, mul, pow now curried; infix syntax for algebraic operations.
haftmann
parents: 22665
diff changeset
   167
  (auto simp add: mkPinj_def split: pol.split)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   168
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   169
text \<open>Negation\<close>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   170
primrec neg :: "pol \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   171
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   172
    "neg (Pc c) = Pc (- c)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   173
  | "neg (Pinj i P) = Pinj i (neg P)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   174
  | "neg (PX P x Q) = PX (neg P) x (neg Q)"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   175
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   176
text \<open>Subtraction\<close>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   177
definition sub :: "pol \<Rightarrow> pol \<Rightarrow> pol"  (infixl "\<langle>-\<rangle>" 65)
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   178
  where "sub P Q = P \<langle>+\<rangle> neg Q"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   179
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   180
text \<open>Square for Fast Exponentiation\<close>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   181
primrec sqr :: "pol \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   182
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   183
    "sqr (Pc c) = Pc (c * c)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   184
  | "sqr (Pinj i P) = mkPinj i (sqr P)"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   185
  | "sqr (PX A x B) = mkPX (sqr A) (x + x) (sqr B) \<langle>+\<rangle> mkPX (Pc 2 \<langle>*\<rangle> A \<langle>*\<rangle> mkPinj 1 B) x (Pc 0)"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   186
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   187
text \<open>Fast Exponentiation\<close>
58710
7216a10d69ba augmented and tuned facts on even/odd and division
haftmann
parents: 58310
diff changeset
   188
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   189
fun pow :: "nat \<Rightarrow> pol \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   190
  where pow_if [simp del]: "pow n P =
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   191
   (if n = 0 then Pc 1
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   192
    else if even n then pow (n div 2) (sqr P)
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   193
    else P \<langle>*\<rangle> pow (n div 2) (sqr P))"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   194
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   195
lemma pow_simps [simp]:
58710
7216a10d69ba augmented and tuned facts on even/odd and division
haftmann
parents: 58310
diff changeset
   196
  "pow 0 P = Pc 1"
58712
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   197
  "pow (2 * n) P = pow n (sqr P)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   198
  "pow (Suc (2 * n)) P = P \<langle>*\<rangle> pow n (sqr P)"
58710
7216a10d69ba augmented and tuned facts on even/odd and division
haftmann
parents: 58310
diff changeset
   199
  by (simp_all add: pow_if)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   200
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   201
lemma even_pow: "even n \<Longrightarrow> pow n P = pow (n div 2) (sqr P)"
58712
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   202
  by (erule evenE) simp
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   203
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   204
lemma odd_pow: "odd n \<Longrightarrow> pow n P = P \<langle>*\<rangle> pow (n div 2) (sqr P)"
58712
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   205
  by (erule oddE) simp
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   206
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   207
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   208
text \<open>Normalization of polynomial expressions\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   209
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   210
primrec norm :: "polex \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   211
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   212
    "norm (Var n) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   213
       (if n = 0 then PX (Pc 1) 1 (Pc 0)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   214
        else Pinj n (PX (Pc 1) 1 (Pc 0)))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   215
  | "norm (Const i) = Pc i"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   216
  | "norm (Add P Q) = norm P \<langle>+\<rangle> norm Q"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   217
  | "norm (Sub P Q) = norm P \<langle>-\<rangle> norm Q"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   218
  | "norm (Mul P Q) = norm P \<langle>*\<rangle> norm Q"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   219
  | "norm (Pow P n) = pow n (norm P)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   220
  | "norm (Neg P) = neg (norm P)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   221
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   222
context cring
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   223
begin
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   224
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   225
text \<open>mkPinj preserve semantics\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   226
lemma mkPinj_ci: "Ipol l (mkPinj a B) = Ipol l (Pinj a B)"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 28952
diff changeset
   227
  by (induct B) (auto simp add: mkPinj_def algebra_simps)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   228
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   229
text \<open>mkPX preserves semantics\<close>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   230
lemma mkPX_ci: "in_carrier l \<Longrightarrow> Ipol l (mkPX A b C) = Ipol l (PX A b C)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   231
  by (cases A) (auto simp add: mkPX_def mkPinj_ci nat_pow_mult [symmetric] m_ac)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   232
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   233
text \<open>Correctness theorems for the implemented operations\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   234
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   235
text \<open>Negation\<close>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   236
lemma neg_ci: "in_carrier l \<Longrightarrow> Ipol l (neg P) = \<ominus> (Ipol l P)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   237
  by (induct P arbitrary: l) (auto simp add: minus_add l_minus)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   238
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   239
text \<open>Addition\<close>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   240
lemma add_ci: "in_carrier l \<Longrightarrow> Ipol l (P \<langle>+\<rangle> Q) = Ipol l P \<oplus> Ipol l Q"
20622
e1a573146be5 tuned proofs;
wenzelm
parents: 19736
diff changeset
   241
proof (induct P Q arbitrary: l rule: add.induct)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   242
  case (6 x P y Q)
60708
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   243
  consider "x < y" | "x = y" | "x > y" by arith
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   244
  then show ?case
60708
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   245
  proof cases
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   246
    case 1
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   247
    with 6 show ?thesis by (simp add: mkPinj_ci a_ac)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   248
  next
60708
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   249
    case 2
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   250
    with 6 show ?thesis by (simp add: mkPinj_ci)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   251
  next
60708
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   252
    case 3
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   253
    with 6 show ?thesis by (simp add: mkPinj_ci)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   254
  qed
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   255
next
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   256
  case (7 x P Q y R)
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   257
  consider "x = 0" | "x = 1" | "x > 1" by arith
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   258
  then show ?case
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   259
  proof cases
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   260
    case 1
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   261
    with 7 show ?thesis by simp
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   262
  next
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   263
    case 2
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   264
    with 7 show ?thesis by (simp add: a_ac)
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   265
  next
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   266
    case 3
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   267
    with 7 show ?thesis by (cases x) (simp_all add: a_ac)
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   268
  qed
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   269
next
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   270
  case (8 P x R y Q)
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   271
  then show ?case by (simp add: a_ac)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   272
next
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   273
  case (9 P1 x P2 Q1 y Q2)
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   274
  consider "x = y" | d where "d + x = y" | d where "d + y = x"
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   275
    by atomize_elim arith
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   276
  then show ?case
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   277
  proof cases
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   278
    case 1
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   279
    with 9 show ?thesis by (simp add: mkPX_ci r_distr a_ac m_ac)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   280
  next
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   281
    case 2
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   282
    with 9 show ?thesis by (auto simp add: mkPX_ci nat_pow_mult [symmetric] r_distr a_ac m_ac)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   283
  next
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   284
    case 3
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   285
    with 9 show ?thesis by (auto simp add: nat_pow_mult [symmetric] mkPX_ci r_distr a_ac m_ac)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   286
  qed
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   287
qed (auto simp add: a_ac m_ac)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   288
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   289
text \<open>Multiplication\<close>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   290
lemma mul_ci: "in_carrier l \<Longrightarrow> Ipol l (P \<langle>*\<rangle> Q) = Ipol l P \<otimes> Ipol l Q"
20622
e1a573146be5 tuned proofs;
wenzelm
parents: 19736
diff changeset
   291
  by (induct P Q arbitrary: l rule: mul.induct)
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   292
    (simp_all add: mkPX_ci mkPinj_ci a_ac m_ac r_distr add_ci nat_pow_mult [symmetric])
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   293
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   294
text \<open>Subtraction\<close>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   295
lemma sub_ci: "in_carrier l \<Longrightarrow> Ipol l (P \<langle>-\<rangle> Q) = Ipol l P \<ominus> Ipol l Q"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   296
  by (simp add: add_ci neg_ci sub_def minus_eq)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   297
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   298
text \<open>Square\<close>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   299
lemma sqr_ci: "in_carrier ls \<Longrightarrow> Ipol ls (sqr P) = Ipol ls P \<otimes> Ipol ls P"
22742
06165e40e7bd switched from recdef to function package; constants add, mul, pow now curried; infix syntax for algebraic operations.
haftmann
parents: 22665
diff changeset
   300
  by (induct P arbitrary: ls)
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   301
    (simp_all add: add_ci mkPinj_ci mkPX_ci mul_ci l_distr r_distr
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   302
       a_ac m_ac nat_pow_mult [symmetric] of_int_2)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   303
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   304
text \<open>Power\<close>
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   305
lemma pow_ci: "in_carrier ls \<Longrightarrow> Ipol ls (pow n P) = Ipol ls P [^] n"
58712
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   306
proof (induct n arbitrary: P rule: less_induct)
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   307
  case (less k)
60708
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   308
  consider "k = 0" | "k > 0" by arith
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   309
  then show ?case
60708
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   310
  proof cases
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   311
    case 1
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   312
    then show ?thesis by simp
20622
e1a573146be5 tuned proofs;
wenzelm
parents: 19736
diff changeset
   313
  next
60708
f425e80a3eb0 tuned proofs;
wenzelm
parents: 60534
diff changeset
   314
    case 2
58712
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   315
    then have "k div 2 < k" by arith
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   316
    with less have *: "Ipol ls (pow (k div 2) (sqr P)) = Ipol ls (sqr P) [^] (k div 2)"
58712
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   317
      by simp
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   318
    show ?thesis
58712
709d8f68ec29 avoid unsafe simp rules
haftmann
parents: 58710
diff changeset
   319
    proof (cases "even k")
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   320
      case True
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   321
      with * \<open>in_carrier ls\<close> show ?thesis
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   322
        by (simp add: even_pow sqr_ci nat_pow_distr nat_pow_mult
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   323
          mult_2 [symmetric] even_two_times_div_two)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   324
    next
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   325
      case False
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   326
      with * \<open>in_carrier ls\<close> show ?thesis
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   327
        by (simp add: odd_pow mul_ci sqr_ci nat_pow_distr nat_pow_mult
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   328
          mult_2 [symmetric] trans [OF nat_pow_Suc m_comm, symmetric])
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   329
    qed
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   330
  qed
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   331
qed
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   332
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   333
text \<open>Normalization preserves semantics\<close>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   334
lemma norm_ci: "in_carrier l \<Longrightarrow> Ipolex l Pe = Ipol l (norm Pe)"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   335
  by (induct Pe) (simp_all add: add_ci sub_ci mul_ci neg_ci pow_ci)
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   336
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 58889
diff changeset
   337
text \<open>Reflection lemma: Key to the (incomplete) decision procedure\<close>
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   338
lemma norm_eq:
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   339
  assumes "in_carrier l"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   340
  and "norm P1 = norm P2"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   341
  shows "Ipolex l P1 = Ipolex l P2"
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   342
proof -
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   343
  from assms have "Ipol l (norm P1) = Ipol l (norm P2)" by simp
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   344
  with assms show ?thesis by (simp only: norm_ci)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   345
qed
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   346
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   347
end
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   348
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   349
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   350
text \<open>Monomials\<close>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   351
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   352
datatype mon =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   353
    Mc int
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   354
  | Minj nat mon
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   355
  | MX nat mon
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   356
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   357
primrec (in cring) Imon :: "'a list \<Rightarrow> mon \<Rightarrow> 'a"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   358
  where
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   359
    "Imon l (Mc c) = \<guillemotleft>c\<guillemotright>"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   360
  | "Imon l (Minj i M) = Imon (drop i l) M"
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   361
  | "Imon l (MX x M) = Imon (drop 1 l) M \<otimes> head l [^] x"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   362
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   363
lemma (in cring) Imon_closed [simp]: "in_carrier l \<Longrightarrow> Imon l m \<in> carrier R"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   364
  by (induct m arbitrary: l) simp_all
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   365
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   366
definition mkMinj :: "nat \<Rightarrow> mon \<Rightarrow> mon"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   367
  where "mkMinj i M =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   368
    (case M of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   369
      Mc c \<Rightarrow> Mc c
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   370
    | Minj j M \<Rightarrow> Minj (i + j) M
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   371
    | _ \<Rightarrow> Minj i M)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   372
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   373
definition Minj_pred :: "nat \<Rightarrow> mon \<Rightarrow> mon"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   374
  where "Minj_pred i M = (if i = 1 then M else mkMinj (i - 1) M)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   375
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   376
primrec mkMX :: "nat \<Rightarrow> mon \<Rightarrow> mon"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   377
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   378
    "mkMX i (Mc c) = MX i (Mc c)"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   379
  | "mkMX i (Minj j M) = (if j = 0 then mkMX i M else MX i (Minj_pred j M))"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   380
  | "mkMX i (MX j M) = MX (i + j) M"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   381
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   382
lemma (in cring) mkMinj_correct: "Imon l (mkMinj i M) = Imon l (Minj i M)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   383
  by (simp add: mkMinj_def add.commute split: mon.split)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   384
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   385
lemma (in cring) Minj_pred_correct: "0 < i \<Longrightarrow> Imon (drop 1 l) (Minj_pred i M) = Imon l (Minj i M)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   386
  by (simp add: Minj_pred_def mkMinj_correct)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   387
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   388
lemma (in cring) mkMX_correct: "in_carrier l \<Longrightarrow> Imon l (mkMX i M) = Imon l M \<otimes> head l [^] i"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   389
  by (induct M)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   390
    (simp_all add: Minj_pred_correct [simplified] nat_pow_mult [symmetric] m_ac split: mon.split)
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   391
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   392
fun cfactor :: "pol \<Rightarrow> int \<Rightarrow> pol \<times> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   393
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   394
    "cfactor (Pc c') c = (Pc (c' mod c), Pc (c' div c))"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   395
  | "cfactor (Pinj i P) c =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   396
       (let (R, S) = cfactor P c
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   397
        in (mkPinj i R, mkPinj i S))"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   398
  | "cfactor (PX P i Q) c =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   399
       (let
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   400
          (R1, S1) = cfactor P c;
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   401
          (R2, S2) = cfactor Q c
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   402
        in (mkPX R1 i R2, mkPX S1 i S2))"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   403
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   404
lemma (in cring) cfactor_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   405
  "in_carrier l \<Longrightarrow> Ipol l P = Ipol l (fst (cfactor P c)) \<oplus> \<guillemotleft>c\<guillemotright> \<otimes> Ipol l (snd (cfactor P c))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   406
proof (induct P c arbitrary: l rule: cfactor.induct)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   407
  case (1 c' c)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   408
  show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   409
    by (simp add: of_int_mult [symmetric] of_int_add [symmetric] del: of_int_mult)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   410
next
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   411
  case (2 i P c)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   412
  then show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   413
    by (simp add: mkPinj_ci split_beta)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   414
next
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   415
  case (3 P i Q c)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   416
  from 3(1) 3(2) [OF refl prod.collapse] 3(3)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   417
  show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   418
    by (simp add: mkPX_ci r_distr a_ac m_ac split_beta)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   419
qed
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   420
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   421
fun mfactor :: "pol \<Rightarrow> mon \<Rightarrow> pol \<times> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   422
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   423
    "mfactor P (Mc c) = (if c = 1 then (Pc 0, P) else cfactor P c)"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   424
  | "mfactor (Pc d) M = (Pc d, Pc 0)"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   425
  | "mfactor (Pinj i P) (Minj j M) =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   426
       (if i = j then
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   427
          let (R, S) = mfactor P M
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   428
          in (mkPinj i R, mkPinj i S)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   429
        else if i < j then
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   430
          let (R, S) = mfactor P (Minj (j - i) M)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   431
          in (mkPinj i R, mkPinj i S)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   432
        else (Pinj i P, Pc 0))"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   433
  | "mfactor (Pinj i P) (MX j M) = (Pinj i P, Pc 0)"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   434
  | "mfactor (PX P i Q) (Minj j M) =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   435
       (if j = 0 then mfactor (PX P i Q) M
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   436
        else
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   437
          let
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   438
            (R1, S1) = mfactor P (Minj j M);
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   439
            (R2, S2) = mfactor Q (Minj_pred j M)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   440
          in (mkPX R1 i R2, mkPX S1 i S2))"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   441
  | "mfactor (PX P i Q) (MX j M) =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   442
       (if i = j then
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   443
          let (R, S) = mfactor P (mkMinj 1 M)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   444
          in (mkPX R i Q, S)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   445
        else if i < j then
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   446
          let (R, S) = mfactor P (MX (j - i) M)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   447
          in (mkPX R i Q, S)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   448
        else
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   449
          let (R, S) = mfactor P (mkMinj 1 M)
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   450
          in (mkPX R i Q, mkPX S (i - j) (Pc 0)))"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   451
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   452
lemmas mfactor_induct = mfactor.induct
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   453
  [case_names Mc Pc_Minj Pc_MX Pinj_Minj Pinj_MX PX_Minj PX_MX]
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   454
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   455
lemma (in cring) mfactor_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   456
  "in_carrier l \<Longrightarrow>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   457
   Ipol l P =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   458
   Ipol l (fst (mfactor P M)) \<oplus>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   459
   Imon l M \<otimes> Ipol l (snd (mfactor P M))"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   460
proof (induct P M arbitrary: l rule: mfactor_induct)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   461
  case (Mc P c)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   462
  then show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   463
    by (simp add: cfactor_correct)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   464
next
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   465
  case (Pc_Minj d i M)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   466
  then show ?case
60534
b2add2b08412 tuned proofs;
wenzelm
parents: 60533
diff changeset
   467
    by simp
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   468
next
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   469
  case (Pc_MX d i M)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   470
  then show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   471
    by simp
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   472
next
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   473
  case (Pinj_Minj i P j M)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   474
  then show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   475
    by (simp add: mkPinj_ci split_beta)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   476
next
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   477
  case (Pinj_MX i P j M)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   478
  then show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   479
    by simp
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   480
next
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   481
  case (PX_Minj P i Q j M)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   482
  from PX_Minj(1,2) PX_Minj(3) [OF _ refl prod.collapse] PX_Minj(4)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   483
  show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   484
    by (simp add: mkPX_ci Minj_pred_correct [simplified] r_distr a_ac m_ac split_beta)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   485
next
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   486
  case (PX_MX P i Q j M)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   487
  from \<open>in_carrier l\<close>
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   488
  have eq1: "(Imon (drop (Suc 0) l) M \<otimes> head l [^] (j - i)) \<otimes>
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   489
    Ipol l (snd (mfactor P (MX (j - i) M))) \<otimes> head l [^] i =
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   490
    Imon (drop (Suc 0) l) M \<otimes>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   491
    Ipol l (snd (mfactor P (MX (j - i) M))) \<otimes>
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   492
    (head l [^] (j - i) \<otimes> head l [^] i)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   493
    by (simp add: m_ac)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   494
  from \<open>in_carrier l\<close>
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   495
  have eq2: "(Imon (drop (Suc 0) l) M \<otimes> head l [^] j) \<otimes>
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   496
    (Ipol l (snd (mfactor P (mkMinj (Suc 0) M))) \<otimes> head l [^] (i - j)) =
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   497
    Imon (drop (Suc 0) l) M \<otimes>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   498
    Ipol l (snd (mfactor P (mkMinj (Suc 0) M))) \<otimes>
67341
df79ef3b3a41 Renamed (^) to [^] in preparation of the move from "op X" to (X)
nipkow
parents: 67123
diff changeset
   499
    (head l [^] (i - j) \<otimes> head l [^] j)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   500
    by (simp add: m_ac)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   501
  from PX_MX \<open>in_carrier l\<close> show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   502
    by (simp add: mkPX_ci mkMinj_correct l_distr eq1 eq2 split_beta nat_pow_mult)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   503
      (simp add: a_ac m_ac)
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   504
qed
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   505
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   506
primrec mon_of_pol :: "pol \<Rightarrow> mon option"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   507
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   508
    "mon_of_pol (Pc c) = Some (Mc c)"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   509
  | "mon_of_pol (Pinj i P) = (case mon_of_pol P of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   510
         None \<Rightarrow> None
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   511
       | Some M \<Rightarrow> Some (mkMinj i M))"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   512
  | "mon_of_pol (PX P i Q) =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   513
       (if Q = Pc 0 then (case mon_of_pol P of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   514
            None \<Rightarrow> None
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   515
          | Some M \<Rightarrow> Some (mkMX i M))
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   516
        else None)"
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   517
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   518
lemma (in cring) mon_of_pol_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   519
  assumes "in_carrier l"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   520
    and "mon_of_pol P = Some M"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   521
  shows "Ipol l P = Imon l M"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   522
  using assms
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   523
proof (induct P arbitrary: M l)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   524
  case (PX P1 i P2)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   525
  from PX(1,3,4)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   526
  show ?case
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   527
    by (auto simp add: mkMinj_correct mkMX_correct split: if_split_asm option.split_asm)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   528
qed (auto simp add: mkMinj_correct split: option.split_asm)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   529
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   530
fun (in cring) Ipolex_polex_list :: "'a list \<Rightarrow> (polex \<times> polex) list \<Rightarrow> bool"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   531
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   532
    "Ipolex_polex_list l [] = True"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   533
  | "Ipolex_polex_list l ((P, Q) # pps) = ((Ipolex l P = Ipolex l Q) \<and> Ipolex_polex_list l pps)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   534
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   535
fun (in cring) Imon_pol_list :: "'a list \<Rightarrow> (mon \<times> pol) list \<Rightarrow> bool"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   536
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   537
    "Imon_pol_list l [] = True"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   538
  | "Imon_pol_list l ((M, P) # mps) = ((Imon l M = Ipol l P) \<and> Imon_pol_list l mps)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   539
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   540
fun mk_monpol_list :: "(polex \<times> polex) list \<Rightarrow> (mon \<times> pol) list"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   541
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   542
    "mk_monpol_list [] = []"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   543
  | "mk_monpol_list ((P, Q) # pps) =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   544
       (case mon_of_pol (norm P) of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   545
          None \<Rightarrow> mk_monpol_list pps
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   546
        | Some M \<Rightarrow> (M, norm Q) # mk_monpol_list pps)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   547
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   548
lemma (in cring) mk_monpol_list_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   549
  "in_carrier l \<Longrightarrow> Ipolex_polex_list l pps \<Longrightarrow> Imon_pol_list l (mk_monpol_list pps)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   550
  by (induct pps rule: mk_monpol_list.induct)
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   551
    (auto split: option.split simp add: norm_ci [symmetric] mon_of_pol_correct [symmetric])
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   552
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   553
definition ponesubst :: "pol \<Rightarrow> mon \<Rightarrow> pol \<Rightarrow> pol option"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   554
  where "ponesubst P1 M P2 =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   555
   (let (Q, R) = mfactor P1 M in
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   556
    (case R of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   557
      Pc c \<Rightarrow> if c = 0 then None else Some (add Q (mul P2 R))
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   558
    | _ \<Rightarrow> Some (add Q (mul P2 R))))"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   559
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   560
fun pnsubst1 :: "pol \<Rightarrow> mon \<Rightarrow> pol \<Rightarrow> nat \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   561
  where "pnsubst1 P1 M P2 n =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   562
    (case ponesubst P1 M P2 of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   563
      None \<Rightarrow> P1
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   564
    | Some P3 \<Rightarrow> if n = 0 then P3 else pnsubst1 P3 M P2 (n - 1))"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   565
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   566
lemma pnsubst1_0 [simp]: "pnsubst1 P1 M P2 0 = (case ponesubst P1 M P2 of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   567
  None \<Rightarrow> P1 | Some P3 \<Rightarrow> P3)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   568
  by (simp split: option.split)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   569
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   570
lemma pnsubst1_Suc [simp]:
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   571
  "pnsubst1 P1 M P2 (Suc n) =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   572
    (case ponesubst P1 M P2 of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   573
      None \<Rightarrow> P1
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   574
    | Some P3 \<Rightarrow> pnsubst1 P3 M P2 n)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   575
  by (simp split: option.split)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   576
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   577
declare pnsubst1.simps [simp del]
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   578
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   579
definition pnsubst :: "pol \<Rightarrow> mon \<Rightarrow> pol \<Rightarrow> nat \<Rightarrow> pol option"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   580
  where "pnsubst P1 M P2 n =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   581
    (case ponesubst P1 M P2 of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   582
      None \<Rightarrow> None
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   583
    | Some P3 \<Rightarrow> Some (pnsubst1 P3 M P2 n))"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   584
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   585
fun psubstl1 :: "pol \<Rightarrow> (mon \<times> pol) list \<Rightarrow> nat \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   586
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   587
    "psubstl1 P1 [] n = P1"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   588
  | "psubstl1 P1 ((M, P2) # mps) n = psubstl1 (pnsubst1 P1 M P2 n) mps n"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   589
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   590
fun psubstl :: "pol \<Rightarrow> (mon \<times> pol) list \<Rightarrow> nat \<Rightarrow> pol option"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   591
  where
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   592
    "psubstl P1 [] n = None"
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   593
  | "psubstl P1 ((M, P2) # mps) n =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   594
      (case pnsubst P1 M P2 n of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   595
        None \<Rightarrow> psubstl P1 mps n
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   596
      | Some P3 \<Rightarrow> Some (psubstl1 P3 mps n))"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   597
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   598
fun pnsubstl :: "pol \<Rightarrow> (mon \<times> pol) list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> pol"
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   599
  where "pnsubstl P1 mps m n =
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   600
    (case psubstl P1 mps n of
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   601
      None \<Rightarrow> P1
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   602
    | Some P3 \<Rightarrow> if m = 0 then P3 else pnsubstl P3 mps (m - 1) n)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   603
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   604
lemma pnsubstl_0 [simp]:
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   605
  "pnsubstl P1 mps 0 n = (case psubstl P1 mps n of None \<Rightarrow> P1 | Some P3 \<Rightarrow> P3)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   606
  by (simp split: option.split)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   607
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   608
lemma pnsubstl_Suc [simp]:
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   609
  "pnsubstl P1 mps (Suc m) n = (case psubstl P1 mps n of None \<Rightarrow> P1 | Some P3 \<Rightarrow> pnsubstl P3 mps m n)"
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   610
  by (simp split: option.split)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   611
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   612
declare pnsubstl.simps [simp del]
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   613
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   614
lemma (in cring) ponesubst_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   615
  "in_carrier l \<Longrightarrow> ponesubst P1 M P2 = Some P3 \<Longrightarrow> Imon l M = Ipol l P2 \<Longrightarrow> Ipol l P1 = Ipol l P3"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   616
  by (auto simp add: ponesubst_def split_beta mfactor_correct [of l P1 M]
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   617
    add_ci mul_ci split: pol.split_asm if_split_asm)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   618
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   619
lemma (in cring) pnsubst1_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   620
  "in_carrier l \<Longrightarrow> Imon l M = Ipol l P2 \<Longrightarrow> Ipol l (pnsubst1 P1 M P2 n) = Ipol l P1"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   621
  by (induct n arbitrary: P1)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   622
    (simp_all add: ponesubst_correct split: option.split)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   623
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   624
lemma (in cring) pnsubst_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   625
  "in_carrier l \<Longrightarrow> pnsubst P1 M P2 n = Some P3 \<Longrightarrow> Imon l M = Ipol l P2 \<Longrightarrow> Ipol l P1 = Ipol l P3"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   626
  by (auto simp add: pnsubst_def
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   627
    pnsubst1_correct ponesubst_correct split: option.split_asm)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   628
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   629
lemma (in cring) psubstl1_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   630
  "in_carrier l \<Longrightarrow> Imon_pol_list l mps \<Longrightarrow> Ipol l (psubstl1 P1 mps n) = Ipol l P1"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   631
  by (induct P1 mps n rule: psubstl1.induct) (simp_all add: pnsubst1_correct)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   632
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   633
lemma (in cring) psubstl_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   634
  "in_carrier l \<Longrightarrow> psubstl P1 mps n = Some P2 \<Longrightarrow> Imon_pol_list l mps \<Longrightarrow> Ipol l P1 = Ipol l P2"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   635
  by (induct P1 mps n rule: psubstl.induct)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   636
    (auto simp add: psubstl1_correct pnsubst_correct split: option.split_asm)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   637
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   638
lemma (in cring) pnsubstl_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   639
  "in_carrier l \<Longrightarrow> Imon_pol_list l mps \<Longrightarrow> Ipol l (pnsubstl P1 mps m n) = Ipol l P1"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   640
  by (induct m arbitrary: P1)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   641
    (simp_all add: psubstl_correct split: option.split)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   642
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   643
lemma (in cring) norm_subst_correct:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   644
  "in_carrier l \<Longrightarrow> Ipolex_polex_list l pps \<Longrightarrow>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   645
   Ipolex l P = Ipol l (pnsubstl (norm P) (mk_monpol_list pps) m n)"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   646
  by (simp add: pnsubstl_correct mk_monpol_list_correct norm_ci)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   647
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   648
lemma in_carrier_trivial: "cring_class.in_carrier l"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   649
  by (induct l) (simp_all add: cring_class.in_carrier_def carrier_class)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   650
64999
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   651
ML \<open>
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   652
val term_of_nat = HOLogic.mk_number @{typ nat} o @{code integer_of_nat};
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   653
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   654
val term_of_int = HOLogic.mk_number @{typ int} o @{code integer_of_int};
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   655
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   656
fun term_of_pol (@{code Pc} k) = @{term Pc} $ term_of_int k
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   657
  | term_of_pol (@{code Pinj} (n, p)) = @{term Pinj} $ term_of_nat n $ term_of_pol p
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   658
  | term_of_pol (@{code PX} (p, n, q)) = @{term PX} $ term_of_pol p $ term_of_nat n $ term_of_pol q;
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   659
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   660
local
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   661
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   662
fun pol (ctxt, ct, t) = Thm.mk_binop @{cterm "Pure.eq :: pol \<Rightarrow> pol \<Rightarrow> prop"}
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   663
  ct (Thm.cterm_of ctxt t);
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   664
64999
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   665
val (_, raw_pol_oracle) = Context.>>> (Context.map_theory_result
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   666
  (Thm.add_oracle (@{binding pnsubstl}, pol)));
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   667
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   668
fun pol_oracle ctxt ct t = raw_pol_oracle (ctxt, ct, t);
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   669
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   670
in
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   671
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   672
val cv = @{computation_conv pol
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   673
  terms: pnsubstl mk_monpol_list norm
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   674
    nat_of_integer Code_Target_Nat.natural
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   675
      "0::nat" "1::nat" "2::nat" "3::nat"
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   676
      "0::int" "1::int" "2::int" "3::int" "-1::int"
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   677
  datatypes: polex "(polex * polex) list" int integer num}
65043
fd753468786f explicit dynamic context for gap-bridging function
haftmann
parents: 64999
diff changeset
   678
  (fn ctxt => fn p => fn ct => pol_oracle ctxt ct (term_of_pol p))
64999
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   679
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   680
end
f8f76a501d25 elaborated examples for computations
haftmann
parents: 64962
diff changeset
   681
\<close>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   682
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   683
ML \<open>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   684
signature RING_TAC =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   685
sig
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   686
  structure Ring_Simps:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   687
  sig
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   688
    type T
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   689
    val get: Context.generic -> T
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   690
    val put: T -> Context.generic -> Context.generic
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   691
    val map: (T -> T) -> Context.generic -> Context.generic
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   692
  end
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   693
  val insert_rules: ((term * 'a) * (term * 'a) -> bool) -> (term * 'a) ->
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   694
    (term * 'a) Net.net -> (term * 'a) Net.net
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   695
  val eq_ring_simps:
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   696
    (term * (thm list * thm list * thm list * thm list * thm * thm)) *
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   697
    (term * (thm list * thm list * thm list * thm list * thm * thm)) -> bool
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   698
  val ring_tac: bool -> thm list -> Proof.context -> int -> tactic
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   699
  val get_matching_rules: Proof.context -> (term * 'a) Net.net -> term -> 'a option
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   700
  val norm: thm -> thm
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   701
  val mk_in_carrier: Proof.context -> term -> thm list -> (string * typ) list -> thm
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   702
  val mk_ring: typ -> term
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   703
end
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   704
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   705
structure Ring_Tac : RING_TAC =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   706
struct
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   707
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   708
fun eq_ring_simps
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   709
  ((t, (ths1, ths2, ths3, ths4, th5, th)),
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   710
   (t', (ths1', ths2', ths3', ths4', th5', th'))) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   711
    t aconv t' andalso
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   712
    eq_list Thm.eq_thm (ths1, ths1') andalso
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   713
    eq_list Thm.eq_thm (ths2, ths2') andalso
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   714
    eq_list Thm.eq_thm (ths3, ths3') andalso
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   715
    eq_list Thm.eq_thm (ths4, ths4') andalso
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   716
    Thm.eq_thm (th5, th5') andalso
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   717
    Thm.eq_thm (th, th');
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   718
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   719
structure Ring_Simps = Generic_Data
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   720
(struct
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   721
  type T = (term * (thm list * thm list * thm list * thm list * thm * thm)) Net.net
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   722
  val empty = Net.empty
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   723
  val extend = I
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   724
  val merge = Net.merge eq_ring_simps
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   725
end);
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   726
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   727
fun get_matching_rules ctxt net t = get_first
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   728
  (fn (p, x) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   729
     if Pattern.matches (Proof_Context.theory_of ctxt) (p, t) then SOME x else NONE)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   730
  (Net.match_term net t);
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   731
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   732
fun insert_rules eq (t, x) = Net.insert_term eq (t, (t, x));
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   733
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   734
fun norm thm = thm COMP_INCR asm_rl;
47432
e1576d13e933 more standard method setup;
wenzelm
parents: 41807
diff changeset
   735
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   736
fun get_ring_simps ctxt optcT t =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   737
  (case get_matching_rules ctxt (Ring_Simps.get (Context.Proof ctxt)) t of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   738
     SOME (ths1, ths2, ths3, ths4, th5, th) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   739
       let val tr =
67649
1e1782c1aedf tuned signature;
wenzelm
parents: 67341
diff changeset
   740
         Thm.transfer' ctxt #>
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   741
         (case optcT of NONE => I | SOME cT => inst [cT] [] #> norm)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   742
       in (map tr ths1, map tr ths2, map tr ths3, map tr ths4, tr th5, tr th) end
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   743
   | NONE => error "get_ring_simps: lookup failed");
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   744
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   745
fun ring_struct (Const (@{const_name Ring.ring.add}, _) $ R $ _ $ _) = SOME R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   746
  | ring_struct (Const (@{const_name Ring.a_minus}, _) $ R $ _ $ _) = SOME R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   747
  | ring_struct (Const (@{const_name Group.monoid.mult}, _) $ R $ _ $ _) = SOME R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   748
  | ring_struct (Const (@{const_name Ring.a_inv}, _) $ R $ _) = SOME R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   749
  | ring_struct (Const (@{const_name Group.pow}, _) $ R $ _ $ _) = SOME R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   750
  | ring_struct (Const (@{const_name Ring.ring.zero}, _) $ R) = SOME R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   751
  | ring_struct (Const (@{const_name Group.monoid.one}, _) $ R) = SOME R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   752
  | ring_struct (Const (@{const_name Algebra_Aux.of_integer}, _) $ R $ _) = SOME R
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   753
  | ring_struct _ = NONE;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   754
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   755
fun reif_polex vs (Const (@{const_name Ring.ring.add}, _) $ _ $ a $ b) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   756
      @{const Add} $ reif_polex vs a $ reif_polex vs b
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   757
  | reif_polex vs (Const (@{const_name Ring.a_minus}, _) $ _ $ a $ b) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   758
      @{const Sub} $ reif_polex vs a $ reif_polex vs b
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   759
  | reif_polex vs (Const (@{const_name Group.monoid.mult}, _) $ _ $ a $ b) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   760
      @{const Mul} $ reif_polex vs a $ reif_polex vs b
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   761
  | reif_polex vs (Const (@{const_name Ring.a_inv}, _) $ _ $ a) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   762
      @{const Neg} $ reif_polex vs a
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   763
  | reif_polex vs (Const (@{const_name Group.pow}, _) $ _ $ a $ n) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   764
      @{const Pow} $ reif_polex vs a $ n
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   765
  | reif_polex vs (Free x) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   766
      @{const Var} $ HOLogic.mk_number HOLogic.natT (find_index (equal x) vs)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   767
  | reif_polex vs (Const (@{const_name Ring.ring.zero}, _) $ _) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   768
      @{term "Const 0"}
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   769
  | reif_polex vs (Const (@{const_name Group.monoid.one}, _) $ _) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   770
      @{term "Const 1"}
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   771
  | reif_polex vs (Const (@{const_name Algebra_Aux.of_integer}, _) $ _ $ n) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   772
      @{const Const} $ n
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   773
  | reif_polex _ _ = error "reif_polex: bad expression";
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   774
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   775
fun reif_polex' vs (Const (@{const_name Groups.plus}, _) $ a $ b) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   776
      @{const Add} $ reif_polex' vs a $ reif_polex' vs b
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   777
  | reif_polex' vs (Const (@{const_name Groups.minus}, _) $ a $ b) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   778
      @{const Sub} $ reif_polex' vs a $ reif_polex' vs b
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   779
  | reif_polex' vs (Const (@{const_name Groups.times}, _) $ a $ b) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   780
      @{const Mul} $ reif_polex' vs a $ reif_polex' vs b
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   781
  | reif_polex' vs (Const (@{const_name Groups.uminus}, _) $ a) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   782
      @{const Neg} $ reif_polex' vs a
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   783
  | reif_polex' vs (Const (@{const_name Power.power}, _) $ a $ n) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   784
      @{const Pow} $ reif_polex' vs a $ n
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   785
  | reif_polex' vs (Free x) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   786
      @{const Var} $ HOLogic.mk_number HOLogic.natT (find_index (equal x) vs)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   787
  | reif_polex' vs (Const (@{const_name numeral}, _) $ b) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   788
      @{const Const} $ (@{const numeral (int)} $ b)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   789
  | reif_polex' vs (Const (@{const_name zero_class.zero}, _)) = @{term "Const 0"}
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   790
  | reif_polex' vs (Const (@{const_name one_class.one}, _)) = @{term "Const 1"}
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   791
  | reif_polex' vs t = error "reif_polex: bad expression";
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   792
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   793
fun head_conv (_, _, _, _, head_simp, _) ys =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   794
  (case strip_app ys of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   795
     (@{const_name Cons}, [y, xs]) => inst [] [y, xs] head_simp);
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   796
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   797
fun Ipol_conv (rls as
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   798
      ([Ipol_simps_1, Ipol_simps_2, Ipol_simps_3,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   799
        Ipol_simps_4, Ipol_simps_5, Ipol_simps_6,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   800
        Ipol_simps_7], _, _, _, _, _)) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   801
  let
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   802
    val a = type_of_eqn Ipol_simps_1;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   803
    val drop_conv_a = drop_conv a;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   804
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   805
    fun conv l p = (case strip_app p of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   806
        (@{const_name Pc}, [c]) => (case strip_numeral c of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   807
            (@{const_name zero_class.zero}, _) => inst [] [l] Ipol_simps_4
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   808
          | (@{const_name one_class.one}, _) => inst [] [l] Ipol_simps_5
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   809
          | (@{const_name numeral}, [m]) => inst [] [l, m] Ipol_simps_6
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   810
          | (@{const_name uminus}, [m]) => inst [] [l, m] Ipol_simps_7
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   811
          | _ => inst [] [l, c] Ipol_simps_1)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   812
      | (@{const_name Pinj}, [i, P]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   813
          transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   814
            (inst [] [l, i, P] Ipol_simps_2)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   815
            (cong2' conv (args2 drop_conv_a) Thm.reflexive)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   816
      | (@{const_name PX}, [P, x, Q]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   817
          transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   818
            (inst [] [l, P, x, Q] Ipol_simps_3)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   819
            (cong2
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   820
               (cong2
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   821
                  (args2 conv) (cong2 (args1 (head_conv rls)) Thm.reflexive))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   822
               (cong2' conv (args2 drop_conv_a) Thm.reflexive)))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   823
  in conv end;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   824
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   825
fun Ipolex_conv (rls as
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   826
      (_,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   827
       [Ipolex_Var, Ipolex_Const, Ipolex_Add,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   828
        Ipolex_Sub, Ipolex_Mul, Ipolex_Pow,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   829
        Ipolex_Neg, Ipolex_Const_0, Ipolex_Const_1,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   830
        Ipolex_Const_numeral], _, _, _, _)) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   831
  let
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   832
    val a = type_of_eqn Ipolex_Var;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   833
    val drop_conv_a = drop_conv a;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   834
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   835
    fun conv l r = (case strip_app r of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   836
        (@{const_name Var}, [n]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   837
          transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   838
            (inst [] [l, n] Ipolex_Var)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   839
            (cong1' (head_conv rls) (args2 drop_conv_a))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   840
      | (@{const_name Const}, [i]) => (case strip_app i of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   841
            (@{const_name zero_class.zero}, _) => inst [] [l] Ipolex_Const_0
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   842
          | (@{const_name one_class.one}, _) => inst [] [l] Ipolex_Const_1
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   843
          | (@{const_name numeral}, [m]) => inst [] [l, m] Ipolex_Const_numeral
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   844
          | _ => inst [] [l, i] Ipolex_Const)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   845
      | (@{const_name Add}, [P, Q]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   846
          transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   847
            (inst [] [l, P, Q] Ipolex_Add)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   848
            (cong2 (args2 conv) (args2 conv))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   849
      | (@{const_name Sub}, [P, Q]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   850
          transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   851
            (inst [] [l, P, Q] Ipolex_Sub)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   852
            (cong2 (args2 conv) (args2 conv))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   853
      | (@{const_name Mul}, [P, Q]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   854
          transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   855
            (inst [] [l, P, Q] Ipolex_Mul)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   856
            (cong2 (args2 conv) (args2 conv))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   857
      | (@{const_name Pow}, [P, n]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   858
          transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   859
            (inst [] [l, P, n] Ipolex_Pow)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   860
            (cong2 (args2 conv) Thm.reflexive)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   861
      | (@{const_name Neg}, [P]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   862
          transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   863
            (inst [] [l, P] Ipolex_Neg)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   864
            (cong1 (args2 conv)))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   865
  in conv end;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   866
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   867
fun Ipolex_polex_list_conv (rls as
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   868
      (_, _,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   869
       [Ipolex_polex_list_Nil, Ipolex_polex_list_Cons], _, _, _)) l pps =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   870
  (case strip_app pps of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   871
     (@{const_name Nil}, []) => inst [] [l] Ipolex_polex_list_Nil
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   872
   | (@{const_name Cons}, [p, pps']) => (case strip_app p of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   873
       (@{const_name Pair}, [P, Q]) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   874
         transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   875
           (inst [] [l, P, Q, pps'] Ipolex_polex_list_Cons)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   876
           (cong2
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   877
              (cong2 (args2 (Ipolex_conv rls)) (args2 (Ipolex_conv rls)))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   878
              (args2 (Ipolex_polex_list_conv rls)))));
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   879
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   880
fun dest_conj th =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   881
  let
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   882
    val th1 = th RS @{thm conjunct1};
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   883
    val th2 = th RS @{thm conjunct2}
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   884
  in
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   885
    dest_conj th1 @ dest_conj th2
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   886
  end handle THM _ => [th];
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   887
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   888
fun mk_in_carrier ctxt R prems xs =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   889
  let
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   890
    val (_, _, _, [in_carrier_Nil, in_carrier_Cons], _, _) =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   891
      get_ring_simps ctxt NONE R;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   892
    val props = map fst (Facts.props (Proof_Context.facts_of ctxt)) @ maps dest_conj prems;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   893
    val ths = map (fn p as (x, _) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   894
      (case find_first
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   895
         ((fn Const (@{const_name Trueprop}, _) $
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   896
                (Const (@{const_name Set.member}, _) $
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   897
                   Free (y, _) $ (Const (@{const_name carrier}, _) $ S)) =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   898
                x = y andalso R aconv S
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   899
            | _ => false) o Thm.prop_of) props of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   900
         SOME th => th
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   901
       | NONE => error ("Variable " ^ Syntax.string_of_term ctxt (Free p) ^
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   902
           " not in carrier"))) xs
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   903
  in
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   904
    fold_rev (fn th1 => fn th2 => [th1, th2] MRS in_carrier_Cons)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   905
       ths in_carrier_Nil
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   906
  end;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   907
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   908
fun mk_ring T =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   909
  Const (@{const_name cring_class_ops},
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   910
    Type (@{type_name partial_object_ext}, [T,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   911
      Type (@{type_name monoid_ext}, [T,
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   912
        Type (@{type_name ring_ext}, [T, @{typ unit}])])]));
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   913
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   914
val iterations = @{cterm "1000::nat"};
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   915
val Trueprop_cong = Thm.combination (Thm.reflexive @{cterm Trueprop});
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   916
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   917
fun commutative_ring_conv ctxt prems eqs ct =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   918
  let
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   919
    val cT = Thm.ctyp_of_cterm ct;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   920
    val T = Thm.typ_of cT;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   921
    val eqs' = map (HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.prop_of) eqs;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   922
    val xs = filter (equal T o snd) (rev (fold Term.add_frees
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   923
      (map fst eqs' @ map snd eqs' @ [Thm.term_of ct]) []));
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   924
    val (R, optcT, prem', reif) = (case ring_struct (Thm.term_of ct) of
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   925
        SOME R => (R, NONE, mk_in_carrier ctxt R prems xs, reif_polex xs)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   926
      | NONE => (mk_ring T, SOME cT, @{thm in_carrier_trivial}, reif_polex' xs));
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   927
    val rls as (_, _, _, _, _, norm_subst_correct) = get_ring_simps ctxt optcT R;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   928
    val cxs = Thm.cterm_of ctxt (HOLogic.mk_list T (map Free xs));
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   929
    val ceqs = Thm.cterm_of ctxt (HOLogic.mk_list @{typ "polex * polex"}
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   930
      (map (HOLogic.mk_prod o apply2 reif) eqs'));
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   931
    val cp = Thm.cterm_of ctxt (reif (Thm.term_of ct));
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   932
    val prem = Thm.equal_elim
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   933
      (Trueprop_cong (Thm.symmetric (Ipolex_polex_list_conv rls cxs ceqs)))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   934
      (fold_rev (fn th1 => fn th2 => [th1, th2] MRS @{thm conjI})
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   935
         eqs @{thm TrueI});
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   936
  in
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   937
    Thm.transitive
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   938
      (Thm.symmetric (Ipolex_conv rls cxs cp))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   939
      (transitive'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   940
         ([prem', prem] MRS inst [] [cxs, ceqs, cp, iterations, iterations]
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   941
            norm_subst_correct)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   942
         (cong2' (Ipol_conv rls)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   943
            Thm.reflexive
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   944
            (cv ctxt)))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   945
  end;
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   946
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   947
fun ring_tac in_prems thms ctxt =
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   948
  tactic_of_conv (fn ct =>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   949
    (if in_prems then Conv.prems_conv else Conv.concl_conv)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   950
      (Logic.count_prems (Thm.term_of ct))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   951
      (Conv.arg_conv (Conv.binop_conv (commutative_ring_conv ctxt [] thms))) ct) THEN'
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   952
  TRY o (assume_tac ctxt ORELSE' resolve_tac ctxt [@{thm refl}]);
17516
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   953
45164074dad4 added Commutative_Ring (from Main HOL);
wenzelm
parents:
diff changeset
   954
end
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   955
\<close>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   956
67123
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   957
context cring
3fe40ff1b921 misc tuning and modernization;
wenzelm
parents: 66453
diff changeset
   958
begin
64962
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   959
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   960
local_setup \<open>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   961
Local_Theory.declaration {syntax = false, pervasive = false}
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   962
  (fn phi => Ring_Tac.Ring_Simps.map (Ring_Tac.insert_rules Ring_Tac.eq_ring_simps
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   963
    (Morphism.term phi @{term R},
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   964
     (Morphism.fact phi @{thms Ipol.simps [meta] Ipol_Pc [meta]},
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   965
      Morphism.fact phi @{thms Ipolex.simps [meta] Ipolex_Const [meta]},
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   966
      Morphism.fact phi @{thms Ipolex_polex_list.simps [meta]},
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   967
      Morphism.fact phi @{thms in_carrier_Nil in_carrier_Cons},
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   968
      singleton (Morphism.fact phi) @{thm head.simps(2) [meta]},
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   969
      singleton (Morphism.fact phi) @{thm norm_subst_correct [meta]}))))
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   970
\<close>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   971
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   972
end
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   973
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   974
method_setup ring = \<open>
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   975
  Scan.lift (Args.mode "prems") -- Attrib.thms >> (SIMPLE_METHOD' oo uncurry Ring_Tac.ring_tac)
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   976
\<close> "simplify equations involving rings"
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   977
bf41e1109db3 Added new / improved tactics for fields and rings
berghofe
parents: 60708
diff changeset
   978
end