src/HOL/Decision_Procs/Ferrack.thy
author hoelzl
Wed, 11 Mar 2009 10:58:18 +0100
changeset 30439 57c68b3af2ea
parent 30042 31039ee583fa
child 30684 c98a64746c69
permissions -rw-r--r--
Updated paths in Decision_Procs comments and NEWS
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30439
57c68b3af2ea Updated paths in Decision_Procs comments and NEWS
hoelzl
parents: 30042
diff changeset
     1
(*  Title:      HOL/Decision_Procs/Ferrack.thy
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
     2
    Author:     Amine Chaieb
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
     3
*)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
     4
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
     5
theory Ferrack
29818
762c2c63fc95 fixed import
chaieb
parents: 29811
diff changeset
     6
imports Complex_Main Dense_Linear_Order Efficient_Nat
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
     7
uses ("ferrack_tac.ML")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
     8
begin
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
     9
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    10
section {* Quantifier elimination for @{text "\<real> (0, 1, +, <)"} *}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    11
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    12
  (*********************************************************************************)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    13
  (*          SOME GENERAL STUFF< HAS TO BE MOVED IN SOME LIB                      *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    14
  (*********************************************************************************)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    15
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    16
consts alluopairs:: "'a list \<Rightarrow> ('a \<times> 'a) list"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    17
primrec
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    18
  "alluopairs [] = []"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    19
  "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    20
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    21
lemma alluopairs_set1: "set (alluopairs xs) \<le> {(x,y). x\<in> set xs \<and> y\<in> set xs}"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    22
by (induct xs, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    23
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    24
lemma alluopairs_set:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    25
  "\<lbrakk>x\<in> set xs ; y \<in> set xs\<rbrakk> \<Longrightarrow> (x,y) \<in> set (alluopairs xs) \<or> (y,x) \<in> set (alluopairs xs) "
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    26
by (induct xs, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    27
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    28
lemma alluopairs_ex:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    29
  assumes Pc: "\<forall> x y. P x y = P y x"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    30
  shows "(\<exists> x \<in> set xs. \<exists> y \<in> set xs. P x y) = (\<exists> (x,y) \<in> set (alluopairs xs). P x y)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    31
proof
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    32
  assume "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    33
  then obtain x y where x: "x \<in> set xs" and y:"y \<in> set xs" and P: "P x y"  by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    34
  from alluopairs_set[OF x y] P Pc show"\<exists>(x, y)\<in>set (alluopairs xs). P x y" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    35
    by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    36
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    37
  assume "\<exists>(x, y)\<in>set (alluopairs xs). P x y"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    38
  then obtain "x" and "y"  where xy:"(x,y) \<in> set (alluopairs xs)" and P: "P x y" by blast+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    39
  from xy have "x \<in> set xs \<and> y\<in> set xs" using alluopairs_set1 by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    40
  with P show "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    41
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    42
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    43
lemma nth_pos2: "0 < n \<Longrightarrow> (x#xs) ! n = xs ! (n - 1)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    44
using Nat.gr0_conv_Suc
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    45
by clarsimp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    46
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    47
lemma filter_length: "length (List.filter P xs) < Suc (length xs)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    48
  apply (induct xs, auto) done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    49
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    50
consts remdps:: "'a list \<Rightarrow> 'a list"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    51
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    52
recdef remdps "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    53
  "remdps [] = []"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    54
  "remdps (x#xs) = (x#(remdps (List.filter (\<lambda> y. y \<noteq> x) xs)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    55
(hints simp add: filter_length[rule_format])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    56
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    57
lemma remdps_set[simp]: "set (remdps xs) = set xs"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    58
  by (induct xs rule: remdps.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    59
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    60
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    61
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    62
  (*********************************************************************************)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    63
  (****                            SHADOW SYNTAX AND SEMANTICS                  ****)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    64
  (*********************************************************************************)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    65
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    66
datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    67
  | Mul int num 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    68
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    69
  (* A size for num to make inductive proofs simpler*)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    70
consts num_size :: "num \<Rightarrow> nat" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    71
primrec 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    72
  "num_size (C c) = 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    73
  "num_size (Bound n) = 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    74
  "num_size (Neg a) = 1 + num_size a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    75
  "num_size (Add a b) = 1 + num_size a + num_size b"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    76
  "num_size (Sub a b) = 3 + num_size a + num_size b"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    77
  "num_size (Mul c a) = 1 + num_size a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    78
  "num_size (CN n c a) = 3 + num_size a "
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    79
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    80
  (* Semantics of numeral terms (num) *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    81
consts Inum :: "real list \<Rightarrow> num \<Rightarrow> real"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    82
primrec
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    83
  "Inum bs (C c) = (real c)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    84
  "Inum bs (Bound n) = bs!n"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    85
  "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    86
  "Inum bs (Neg a) = -(Inum bs a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    87
  "Inum bs (Add a b) = Inum bs a + Inum bs b"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    88
  "Inum bs (Sub a b) = Inum bs a - Inum bs b"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    89
  "Inum bs (Mul c a) = (real c) * Inum bs a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    90
    (* FORMULAE *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    91
datatype fm  = 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    92
  T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num|
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    93
  NOT fm| And fm fm|  Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    94
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    95
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    96
  (* A size for fm *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    97
consts fmsize :: "fm \<Rightarrow> nat"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    98
recdef fmsize "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    99
  "fmsize (NOT p) = 1 + fmsize p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   100
  "fmsize (And p q) = 1 + fmsize p + fmsize q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   101
  "fmsize (Or p q) = 1 + fmsize p + fmsize q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   102
  "fmsize (Imp p q) = 3 + fmsize p + fmsize q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   103
  "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   104
  "fmsize (E p) = 1 + fmsize p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   105
  "fmsize (A p) = 4+ fmsize p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   106
  "fmsize p = 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   107
  (* several lemmas about fmsize *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   108
lemma fmsize_pos: "fmsize p > 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   109
by (induct p rule: fmsize.induct) simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   110
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   111
  (* Semantics of formulae (fm) *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   112
consts Ifm ::"real list \<Rightarrow> fm \<Rightarrow> bool"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   113
primrec
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   114
  "Ifm bs T = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   115
  "Ifm bs F = False"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   116
  "Ifm bs (Lt a) = (Inum bs a < 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   117
  "Ifm bs (Gt a) = (Inum bs a > 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   118
  "Ifm bs (Le a) = (Inum bs a \<le> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   119
  "Ifm bs (Ge a) = (Inum bs a \<ge> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   120
  "Ifm bs (Eq a) = (Inum bs a = 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   121
  "Ifm bs (NEq a) = (Inum bs a \<noteq> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   122
  "Ifm bs (NOT p) = (\<not> (Ifm bs p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   123
  "Ifm bs (And p q) = (Ifm bs p \<and> Ifm bs q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   124
  "Ifm bs (Or p q) = (Ifm bs p \<or> Ifm bs q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   125
  "Ifm bs (Imp p q) = ((Ifm bs p) \<longrightarrow> (Ifm bs q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   126
  "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   127
  "Ifm bs (E p) = (\<exists> x. Ifm (x#bs) p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   128
  "Ifm bs (A p) = (\<forall> x. Ifm (x#bs) p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   129
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   130
lemma IfmLeSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Le (Sub s t)) = (s' \<le> t')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   131
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   132
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   133
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   134
lemma IfmLtSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Lt (Sub s t)) = (s' < t')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   135
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   136
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   137
lemma IfmEqSub: "\<lbrakk> Inum bs s = s' ; Inum bs t = t' \<rbrakk> \<Longrightarrow> Ifm bs (Eq (Sub s t)) = (s' = t')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   138
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   139
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   140
lemma IfmNOT: " (Ifm bs p = P) \<Longrightarrow> (Ifm bs (NOT p) = (\<not>P))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   141
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   142
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   143
lemma IfmAnd: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (And p q) = (P \<and> Q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   144
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   145
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   146
lemma IfmOr: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Or p q) = (P \<or> Q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   147
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   148
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   149
lemma IfmImp: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Imp p q) = (P \<longrightarrow> Q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   150
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   151
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   152
lemma IfmIff: " \<lbrakk> Ifm bs p = P ; Ifm bs q = Q\<rbrakk> \<Longrightarrow> (Ifm bs (Iff p q) = (P = Q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   153
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   154
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   155
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   156
lemma IfmE: " (!! x. Ifm (x#bs) p = P x) \<Longrightarrow> (Ifm bs (E p) = (\<exists>x. P x))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   157
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   158
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   159
lemma IfmA: " (!! x. Ifm (x#bs) p = P x) \<Longrightarrow> (Ifm bs (A p) = (\<forall>x. P x))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   160
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   161
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   162
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   163
consts not:: "fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   164
recdef not "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   165
  "not (NOT p) = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   166
  "not T = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   167
  "not F = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   168
  "not p = NOT p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   169
lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   170
by (cases p) auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   171
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   172
constdefs conj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   173
  "conj p q \<equiv> (if (p = F \<or> q=F) then F else if p=T then q else if q=T then p else 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   174
   if p = q then p else And p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   175
lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   176
by (cases "p=F \<or> q=F",simp_all add: conj_def) (cases p,simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   177
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   178
constdefs disj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   179
  "disj p q \<equiv> (if (p = T \<or> q=T) then T else if p=F then q else if q=F then p 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   180
       else if p=q then p else Or p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   181
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   182
lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   183
by (cases "p=T \<or> q=T",simp_all add: disj_def) (cases p,simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   184
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   185
constdefs  imp :: "fm \<Rightarrow> fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   186
  "imp p q \<equiv> (if (p = F \<or> q=T \<or> p=q) then T else if p=T then q else if q=F then not p 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   187
    else Imp p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   188
lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   189
by (cases "p=F \<or> q=T",simp_all add: imp_def) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   190
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   191
constdefs   iff :: "fm \<Rightarrow> fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   192
  "iff p q \<equiv> (if (p = q) then T else if (p = NOT q \<or> NOT p = q) then F else 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   193
       if p=F then not q else if q=F then not p else if p=T then q else if q=T then p else 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   194
  Iff p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   195
lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   196
  by (unfold iff_def,cases "p=q", simp,cases "p=NOT q", simp) (cases "NOT p= q", auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   197
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   198
lemma conj_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   199
  "conj F Q = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   200
  "conj P F = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   201
  "conj T Q = Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   202
  "conj P T = P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   203
  "conj P P = P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   204
  "P \<noteq> T \<Longrightarrow> P \<noteq> F \<Longrightarrow> Q \<noteq> T \<Longrightarrow> Q \<noteq> F \<Longrightarrow> P \<noteq> Q \<Longrightarrow> conj P Q = And P Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   205
  by (simp_all add: conj_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   206
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   207
lemma disj_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   208
  "disj T Q = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   209
  "disj P T = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   210
  "disj F Q = Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   211
  "disj P F = P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   212
  "disj P P = P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   213
  "P \<noteq> T \<Longrightarrow> P \<noteq> F \<Longrightarrow> Q \<noteq> T \<Longrightarrow> Q \<noteq> F \<Longrightarrow> P \<noteq> Q \<Longrightarrow> disj P Q = Or P Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   214
  by (simp_all add: disj_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   215
lemma imp_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   216
  "imp F Q = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   217
  "imp P T = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   218
  "imp T Q = Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   219
  "imp P F = not P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   220
  "imp P P = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   221
  "P \<noteq> T \<Longrightarrow> P \<noteq> F \<Longrightarrow> P \<noteq> Q \<Longrightarrow> Q \<noteq> T \<Longrightarrow> Q \<noteq> F \<Longrightarrow> imp P Q = Imp P Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   222
  by (simp_all add: imp_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   223
lemma trivNOT: "p \<noteq> NOT p" "NOT p \<noteq> p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   224
apply (induct p, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   225
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   226
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   227
lemma iff_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   228
  "iff p p = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   229
  "iff p (NOT p) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   230
  "iff (NOT p) p = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   231
  "iff p F = not p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   232
  "iff F p = not p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   233
  "p \<noteq> NOT T \<Longrightarrow> iff T p = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   234
  "p\<noteq> NOT T \<Longrightarrow> iff p T = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   235
  "p\<noteq>q \<Longrightarrow> p\<noteq> NOT q \<Longrightarrow> q\<noteq> NOT p \<Longrightarrow> p\<noteq> F \<Longrightarrow> q\<noteq> F \<Longrightarrow> p \<noteq> T \<Longrightarrow> q \<noteq> T \<Longrightarrow> iff p q = Iff p q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   236
  using trivNOT
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   237
  by (simp_all add: iff_def, cases p, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   238
  (* Quantifier freeness *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   239
consts qfree:: "fm \<Rightarrow> bool"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   240
recdef qfree "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   241
  "qfree (E p) = False"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   242
  "qfree (A p) = False"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   243
  "qfree (NOT p) = qfree p" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   244
  "qfree (And p q) = (qfree p \<and> qfree q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   245
  "qfree (Or  p q) = (qfree p \<and> qfree q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   246
  "qfree (Imp p q) = (qfree p \<and> qfree q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   247
  "qfree (Iff p q) = (qfree p \<and> qfree q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   248
  "qfree p = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   249
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   250
  (* Boundedness and substitution *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   251
consts 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   252
  numbound0:: "num \<Rightarrow> bool" (* a num is INDEPENDENT of Bound 0 *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   253
  bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   254
primrec
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   255
  "numbound0 (C c) = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   256
  "numbound0 (Bound n) = (n>0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   257
  "numbound0 (CN n c a) = (n\<noteq>0 \<and> numbound0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   258
  "numbound0 (Neg a) = numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   259
  "numbound0 (Add a b) = (numbound0 a \<and> numbound0 b)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   260
  "numbound0 (Sub a b) = (numbound0 a \<and> numbound0 b)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   261
  "numbound0 (Mul i a) = numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   262
lemma numbound0_I:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   263
  assumes nb: "numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   264
  shows "Inum (b#bs) a = Inum (b'#bs) a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   265
using nb
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   266
by (induct a rule: numbound0.induct,auto simp add: nth_pos2)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   267
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   268
primrec
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   269
  "bound0 T = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   270
  "bound0 F = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   271
  "bound0 (Lt a) = numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   272
  "bound0 (Le a) = numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   273
  "bound0 (Gt a) = numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   274
  "bound0 (Ge a) = numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   275
  "bound0 (Eq a) = numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   276
  "bound0 (NEq a) = numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   277
  "bound0 (NOT p) = bound0 p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   278
  "bound0 (And p q) = (bound0 p \<and> bound0 q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   279
  "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   280
  "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   281
  "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   282
  "bound0 (E p) = False"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   283
  "bound0 (A p) = False"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   284
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   285
lemma bound0_I:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   286
  assumes bp: "bound0 p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   287
  shows "Ifm (b#bs) p = Ifm (b'#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   288
using bp numbound0_I[where b="b" and bs="bs" and b'="b'"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   289
by (induct p rule: bound0.induct) (auto simp add: nth_pos2)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   290
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   291
lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   292
by (cases p, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   293
lemma not_bn[simp]: "bound0 p \<Longrightarrow> bound0 (not p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   294
by (cases p, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   295
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   296
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   297
lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   298
using conj_def by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   299
lemma conj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   300
using conj_def by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   301
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   302
lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   303
using disj_def by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   304
lemma disj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   305
using disj_def by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   306
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   307
lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   308
using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   309
lemma imp_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   310
using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   311
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   312
lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   313
  by (unfold iff_def,cases "p=q", auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   314
lemma iff_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   315
using iff_def by (unfold iff_def,cases "p=q", auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   316
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   317
consts 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   318
  decrnum:: "num \<Rightarrow> num" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   319
  decr :: "fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   320
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   321
recdef decrnum "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   322
  "decrnum (Bound n) = Bound (n - 1)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   323
  "decrnum (Neg a) = Neg (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   324
  "decrnum (Add a b) = Add (decrnum a) (decrnum b)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   325
  "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   326
  "decrnum (Mul c a) = Mul c (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   327
  "decrnum (CN n c a) = CN (n - 1) c (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   328
  "decrnum a = a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   329
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   330
recdef decr "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   331
  "decr (Lt a) = Lt (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   332
  "decr (Le a) = Le (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   333
  "decr (Gt a) = Gt (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   334
  "decr (Ge a) = Ge (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   335
  "decr (Eq a) = Eq (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   336
  "decr (NEq a) = NEq (decrnum a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   337
  "decr (NOT p) = NOT (decr p)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   338
  "decr (And p q) = conj (decr p) (decr q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   339
  "decr (Or p q) = disj (decr p) (decr q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   340
  "decr (Imp p q) = imp (decr p) (decr q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   341
  "decr (Iff p q) = iff (decr p) (decr q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   342
  "decr p = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   343
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   344
lemma decrnum: assumes nb: "numbound0 t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   345
  shows "Inum (x#bs) t = Inum bs (decrnum t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   346
  using nb by (induct t rule: decrnum.induct, simp_all add: nth_pos2)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   347
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   348
lemma decr: assumes nb: "bound0 p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   349
  shows "Ifm (x#bs) p = Ifm bs (decr p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   350
  using nb 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   351
  by (induct p rule: decr.induct, simp_all add: nth_pos2 decrnum)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   352
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   353
lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   354
by (induct p, simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   355
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   356
consts 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   357
  isatom :: "fm \<Rightarrow> bool" (* test for atomicity *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   358
recdef isatom "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   359
  "isatom T = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   360
  "isatom F = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   361
  "isatom (Lt a) = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   362
  "isatom (Le a) = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   363
  "isatom (Gt a) = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   364
  "isatom (Ge a) = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   365
  "isatom (Eq a) = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   366
  "isatom (NEq a) = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   367
  "isatom p = False"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   368
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   369
lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   370
by (induct p, simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   371
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   372
constdefs djf:: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   373
  "djf f p q \<equiv> (if q=T then T else if q=F then f p else 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   374
  (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   375
constdefs evaldjf:: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   376
  "evaldjf f ps \<equiv> foldr (djf f) ps F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   377
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   378
lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   379
by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   380
(cases "f p", simp_all add: Let_def djf_def) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   381
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   382
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   383
lemma djf_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   384
  "djf f p T = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   385
  "djf f p F = f p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   386
  "q\<noteq>T \<Longrightarrow> q\<noteq>F \<Longrightarrow> djf f p q = (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   387
  by (simp_all add: djf_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   388
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   389
lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\<exists> p \<in> set ps. Ifm bs (f p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   390
  by(induct ps, simp_all add: evaldjf_def djf_Or)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   391
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   392
lemma evaldjf_bound0: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   393
  assumes nb: "\<forall> x\<in> set xs. bound0 (f x)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   394
  shows "bound0 (evaldjf f xs)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   395
  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   396
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   397
lemma evaldjf_qf: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   398
  assumes nb: "\<forall> x\<in> set xs. qfree (f x)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   399
  shows "qfree (evaldjf f xs)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   400
  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   401
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   402
consts disjuncts :: "fm \<Rightarrow> fm list"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   403
recdef disjuncts "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   404
  "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   405
  "disjuncts F = []"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   406
  "disjuncts p = [p]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   407
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   408
lemma disjuncts: "(\<exists> q\<in> set (disjuncts p). Ifm bs q) = Ifm bs p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   409
by(induct p rule: disjuncts.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   410
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   411
lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). bound0 q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   412
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   413
  assume nb: "bound0 p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   414
  hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   415
  thus ?thesis by (simp only: list_all_iff)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   416
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   417
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   418
lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   419
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   420
  assume qf: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   421
  hence "list_all qfree (disjuncts p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   422
    by (induct p rule: disjuncts.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   423
  thus ?thesis by (simp only: list_all_iff)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   424
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   425
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   426
constdefs DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   427
  "DJ f p \<equiv> evaldjf f (disjuncts p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   428
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   429
lemma DJ: assumes fdj: "\<forall> p q. Ifm bs (f (Or p q)) = Ifm bs (Or (f p) (f q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   430
  and fF: "f F = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   431
  shows "Ifm bs (DJ f p) = Ifm bs (f p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   432
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   433
  have "Ifm bs (DJ f p) = (\<exists> q \<in> set (disjuncts p). Ifm bs (f q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   434
    by (simp add: DJ_def evaldjf_ex) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   435
  also have "\<dots> = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   436
  finally show ?thesis .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   437
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   438
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   439
lemma DJ_qf: assumes 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   440
  fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   441
  shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   442
proof(clarify)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   443
  fix  p assume qf: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   444
  have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   445
  from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   446
  with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   447
  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   448
  from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   449
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   450
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   451
lemma DJ_qe: assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   452
  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bs ((DJ qe p)) = Ifm bs (E p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   453
proof(clarify)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   454
  fix p::fm and bs
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   455
  assume qf: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   456
  from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   457
  from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   458
  have "Ifm bs (DJ qe p) = (\<exists> q\<in> set (disjuncts p). Ifm bs (qe q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   459
    by (simp add: DJ_def evaldjf_ex)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   460
  also have "\<dots> = (\<exists> q \<in> set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   461
  also have "\<dots> = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   462
  finally show "qfree (DJ qe p) \<and> Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   463
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   464
  (* Simplification *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   465
consts 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   466
  numgcd :: "num \<Rightarrow> int"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   467
  numgcdh:: "num \<Rightarrow> int \<Rightarrow> int"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   468
  reducecoeffh:: "num \<Rightarrow> int \<Rightarrow> num"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   469
  reducecoeff :: "num \<Rightarrow> num"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   470
  dvdnumcoeff:: "num \<Rightarrow> int \<Rightarrow> bool"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   471
consts maxcoeff:: "num \<Rightarrow> int"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   472
recdef maxcoeff "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   473
  "maxcoeff (C i) = abs i"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   474
  "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   475
  "maxcoeff t = 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   476
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   477
lemma maxcoeff_pos: "maxcoeff t \<ge> 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   478
  by (induct t rule: maxcoeff.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   479
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   480
recdef numgcdh "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   481
  "numgcdh (C i) = (\<lambda>g. zgcd i g)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   482
  "numgcdh (CN n c t) = (\<lambda>g. zgcd c (numgcdh t g))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   483
  "numgcdh t = (\<lambda>g. 1)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   484
defs numgcd_def [code]: "numgcd t \<equiv> numgcdh t (maxcoeff t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   485
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   486
recdef reducecoeffh "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   487
  "reducecoeffh (C i) = (\<lambda> g. C (i div g))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   488
  "reducecoeffh (CN n c t) = (\<lambda> g. CN n (c div g) (reducecoeffh t g))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   489
  "reducecoeffh t = (\<lambda>g. t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   490
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   491
defs reducecoeff_def: "reducecoeff t \<equiv> 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   492
  (let g = numgcd t in 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   493
  if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   494
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   495
recdef dvdnumcoeff "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   496
  "dvdnumcoeff (C i) = (\<lambda> g. g dvd i)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   497
  "dvdnumcoeff (CN n c t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   498
  "dvdnumcoeff t = (\<lambda>g. False)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   499
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   500
lemma dvdnumcoeff_trans: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   501
  assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   502
  shows "dvdnumcoeff t g"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   503
  using dgt' gdg 
30042
31039ee583fa Removed subsumed lemmas
nipkow
parents: 29823
diff changeset
   504
  by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg dvd_trans[OF gdg])
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   505
30042
31039ee583fa Removed subsumed lemmas
nipkow
parents: 29823
diff changeset
   506
declare dvd_trans [trans add]
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   507
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   508
lemma natabs0: "(nat (abs x) = 0) = (x = 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   509
by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   510
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   511
lemma numgcd0:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   512
  assumes g0: "numgcd t = 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   513
  shows "Inum bs t = 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   514
  using g0[simplified numgcd_def] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   515
  by (induct t rule: numgcdh.induct, auto simp add: zgcd_def gcd_zero natabs0 max_def maxcoeff_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   516
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   517
lemma numgcdh_pos: assumes gp: "g \<ge> 0" shows "numgcdh t g \<ge> 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   518
  using gp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   519
  by (induct t rule: numgcdh.induct, auto simp add: zgcd_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   520
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   521
lemma numgcd_pos: "numgcd t \<ge>0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   522
  by (simp add: numgcd_def numgcdh_pos maxcoeff_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   523
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   524
lemma reducecoeffh:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   525
  assumes gt: "dvdnumcoeff t g" and gp: "g > 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   526
  shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   527
  using gt
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   528
proof(induct t rule: reducecoeffh.induct) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   529
  case (1 i) hence gd: "g dvd i" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   530
  from gp have gnz: "g \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   531
  from prems show ?case by (simp add: real_of_int_div[OF gnz gd])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   532
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   533
  case (2 n c t)  hence gd: "g dvd c" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   534
  from gp have gnz: "g \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   535
  from prems show ?case by (simp add: real_of_int_div[OF gnz gd] algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   536
qed (auto simp add: numgcd_def gp)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   537
consts ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   538
recdef ismaxcoeff "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   539
  "ismaxcoeff (C i) = (\<lambda> x. abs i \<le> x)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   540
  "ismaxcoeff (CN n c t) = (\<lambda>x. abs c \<le> x \<and> (ismaxcoeff t x))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   541
  "ismaxcoeff t = (\<lambda>x. True)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   542
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   543
lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   544
by (induct t rule: ismaxcoeff.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   545
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   546
lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   547
proof (induct t rule: maxcoeff.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   548
  case (2 n c t)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   549
  hence H:"ismaxcoeff t (maxcoeff t)" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   550
  have thh: "maxcoeff t \<le> max (abs c) (maxcoeff t)" by (simp add: le_maxI2)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   551
  from ismaxcoeff_mono[OF H thh] show ?case by (simp add: le_maxI1)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   552
qed simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   553
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   554
lemma zgcd_gt1: "zgcd i j > 1 \<Longrightarrow> ((abs i > 1 \<and> abs j > 1) \<or> (abs i = 0 \<and> abs j > 1) \<or> (abs i > 1 \<and> abs j = 0))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   555
  apply (cases "abs i = 0", simp_all add: zgcd_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   556
  apply (cases "abs j = 0", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   557
  apply (cases "abs i = 1", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   558
  apply (cases "abs j = 1", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   559
  apply auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   560
  done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   561
lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow>  m =0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   562
  by (induct t rule: numgcdh.induct, auto simp add:zgcd0)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   563
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   564
lemma dvdnumcoeff_aux:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   565
  assumes "ismaxcoeff t m" and mp:"m \<ge> 0" and "numgcdh t m > 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   566
  shows "dvdnumcoeff t (numgcdh t m)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   567
using prems
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   568
proof(induct t rule: numgcdh.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   569
  case (2 n c t) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   570
  let ?g = "numgcdh t m"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   571
  from prems have th:"zgcd c ?g > 1" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   572
  from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   573
  have "(abs c > 1 \<and> ?g > 1) \<or> (abs c = 0 \<and> ?g > 1) \<or> (abs c > 1 \<and> ?g = 0)" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   574
  moreover {assume "abs c > 1" and gp: "?g > 1" with prems
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   575
    have th: "dvdnumcoeff t ?g" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   576
    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   577
    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   578
  moreover {assume "abs c = 0 \<and> ?g > 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   579
    with prems have th: "dvdnumcoeff t ?g" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   580
    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   581
    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   582
    hence ?case by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   583
  moreover {assume "abs c > 1" and g0:"?g = 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   584
    from numgcdh0[OF g0] have "m=0". with prems   have ?case by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   585
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   586
qed(auto simp add: zgcd_zdvd1)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   587
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   588
lemma dvdnumcoeff_aux2:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   589
  assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) \<and> numgcd t > 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   590
  using prems 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   591
proof (simp add: numgcd_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   592
  let ?mc = "maxcoeff t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   593
  let ?g = "numgcdh t ?mc"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   594
  have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   595
  have th2: "?mc \<ge> 0" by (rule maxcoeff_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   596
  assume H: "numgcdh t ?mc > 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   597
  from dvdnumcoeff_aux[OF th1 th2 H]  show "dvdnumcoeff t ?g" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   598
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   599
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   600
lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   601
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   602
  let ?g = "numgcd t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   603
  have "?g \<ge> 0"  by (simp add: numgcd_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   604
  hence	"?g = 0 \<or> ?g = 1 \<or> ?g > 1" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   605
  moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)} 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   606
  moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)} 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   607
  moreover { assume g1:"?g > 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   608
    from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   609
    from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   610
      by (simp add: reducecoeff_def Let_def)} 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   611
  ultimately show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   612
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   613
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   614
lemma reducecoeffh_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeffh t g)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   615
by (induct t rule: reducecoeffh.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   616
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   617
lemma reducecoeff_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeff t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   618
using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   619
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   620
consts
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   621
  simpnum:: "num \<Rightarrow> num"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   622
  numadd:: "num \<times> num \<Rightarrow> num"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   623
  nummul:: "num \<Rightarrow> int \<Rightarrow> num"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   624
recdef numadd "measure (\<lambda> (t,s). size t + size s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   625
  "numadd (CN n1 c1 r1,CN n2 c2 r2) =
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   626
  (if n1=n2 then 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   627
  (let c = c1 + c2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   628
  in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2))))
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   629
  else if n1 \<le> n2 then (CN n1 c1 (numadd (r1,CN n2 c2 r2))) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   630
  else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   631
  "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))"  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   632
  "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   633
  "numadd (C b1, C b2) = C (b1+b2)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   634
  "numadd (a,b) = Add a b"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   635
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   636
lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   637
apply (induct t s rule: numadd.induct, simp_all add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   638
apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   639
apply (case_tac "n1 = n2", simp_all add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   640
by (simp only: left_distrib[symmetric],simp)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   641
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   642
lemma numadd_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   643
by (induct t s rule: numadd.induct, auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   644
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   645
recdef nummul "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   646
  "nummul (C j) = (\<lambda> i. C (i*j))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   647
  "nummul (CN n c a) = (\<lambda> i. CN n (i*c) (nummul a i))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   648
  "nummul t = (\<lambda> i. Mul i t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   649
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   650
lemma nummul[simp]: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   651
by (induct t rule: nummul.induct, auto simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   652
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   653
lemma nummul_nb[simp]: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   654
by (induct t rule: nummul.induct, auto )
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   655
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   656
constdefs numneg :: "num \<Rightarrow> num"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   657
  "numneg t \<equiv> nummul t (- 1)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   658
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   659
constdefs numsub :: "num \<Rightarrow> num \<Rightarrow> num"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   660
  "numsub s t \<equiv> (if s = t then C 0 else numadd (s,numneg t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   661
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   662
lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   663
using numneg_def by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   664
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   665
lemma numneg_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numneg t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   666
using numneg_def by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   667
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   668
lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   669
using numsub_def by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   670
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   671
lemma numsub_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numsub t s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   672
using numsub_def by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   673
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   674
recdef simpnum "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   675
  "simpnum (C j) = C j"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   676
  "simpnum (Bound n) = CN n 1 (C 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   677
  "simpnum (Neg t) = numneg (simpnum t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   678
  "simpnum (Add t s) = numadd (simpnum t,simpnum s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   679
  "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   680
  "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   681
  "simpnum (CN n c t) = (if c = 0 then simpnum t else numadd (CN n c (C 0),simpnum t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   682
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   683
lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   684
by (induct t rule: simpnum.induct, auto simp add: numneg numadd numsub nummul)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   685
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   686
lemma simpnum_numbound0[simp]: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   687
  "numbound0 t \<Longrightarrow> numbound0 (simpnum t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   688
by (induct t rule: simpnum.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   689
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   690
consts nozerocoeff:: "num \<Rightarrow> bool"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   691
recdef nozerocoeff "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   692
  "nozerocoeff (C c) = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   693
  "nozerocoeff (CN n c t) = (c\<noteq>0 \<and> nozerocoeff t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   694
  "nozerocoeff t = True"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   695
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   696
lemma numadd_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numadd (a,b))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   697
by (induct a b rule: numadd.induct,auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   698
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   699
lemma nummul_nz : "\<And> i. i\<noteq>0 \<Longrightarrow> nozerocoeff a \<Longrightarrow> nozerocoeff (nummul a i)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   700
by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   701
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   702
lemma numneg_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff (numneg a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   703
by (simp add: numneg_def nummul_nz)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   704
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   705
lemma numsub_nz: "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numsub a b)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   706
by (simp add: numsub_def numneg_nz numadd_nz)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   707
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   708
lemma simpnum_nz: "nozerocoeff (simpnum t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   709
by(induct t rule: simpnum.induct, auto simp add: numadd_nz numneg_nz numsub_nz nummul_nz)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   710
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   711
lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   712
proof (induct t rule: maxcoeff.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   713
  case (2 n c t)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   714
  hence cnz: "c \<noteq>0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   715
  have "max (abs c) (maxcoeff t) \<ge> abs c" by (simp add: le_maxI1)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   716
  with cnz have "max (abs c) (maxcoeff t) > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   717
  with prems show ?case by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   718
qed auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   719
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   720
lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   721
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   722
  from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   723
  from numgcdh0[OF th]  have th:"maxcoeff t = 0" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   724
  from maxcoeff_nz[OF nz th] show ?thesis .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   725
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   726
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   727
constdefs simp_num_pair:: "(num \<times> int) \<Rightarrow> num \<times> int"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   728
  "simp_num_pair \<equiv> (\<lambda> (t,n). (if n = 0 then (C 0, 0) else
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   729
   (let t' = simpnum t ; g = numgcd t' in 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   730
      if g > 1 then (let g' = zgcd n g in 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   731
        if g' = 1 then (t',n) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   732
        else (reducecoeffh t' g', n div g')) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   733
      else (t',n))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   734
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   735
lemma simp_num_pair_ci:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   736
  shows "((\<lambda> (t,n). Inum bs t / real n) (simp_num_pair (t,n))) = ((\<lambda> (t,n). Inum bs t / real n) (t,n))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   737
  (is "?lhs = ?rhs")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   738
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   739
  let ?t' = "simpnum t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   740
  let ?g = "numgcd ?t'"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   741
  let ?g' = "zgcd n ?g"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   742
  {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   743
  moreover
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   744
  { assume nnz: "n \<noteq> 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   745
    {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   746
    moreover
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   747
    {assume g1:"?g>1" hence g0: "?g > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   748
      from zgcd0 g1 nnz have gp0: "?g' \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   749
      hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   750
      hence "?g'= 1 \<or> ?g' > 1" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   751
      moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def simpnum_ci)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   752
      moreover {assume g'1:"?g'>1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   753
	from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" ..
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   754
	let ?tt = "reducecoeffh ?t' ?g'"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   755
	let ?t = "Inum bs ?tt"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   756
	have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   757
	have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   758
	have gpdgp: "?g' dvd ?g'" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   759
	from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   760
	have th2:"real ?g' * ?t = Inum bs ?t'" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   761
	from prems have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   762
	also have "\<dots> = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   763
	also have "\<dots> = (Inum bs ?t' / real n)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   764
	  using real_of_int_div[OF gp0 gpdd] th2 gp0 by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   765
	finally have "?lhs = Inum bs t / real n" by (simp add: simpnum_ci)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   766
	then have ?thesis using prems by (simp add: simp_num_pair_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   767
      ultimately have ?thesis by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   768
    ultimately have ?thesis by blast} 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   769
  ultimately show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   770
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   771
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   772
lemma simp_num_pair_l: assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   773
  shows "numbound0 t' \<and> n' >0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   774
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   775
    let ?t' = "simpnum t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   776
  let ?g = "numgcd ?t'"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   777
  let ?g' = "zgcd n ?g"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   778
  {assume nz: "n = 0" hence ?thesis using prems by (simp add: Let_def simp_num_pair_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   779
  moreover
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   780
  { assume nnz: "n \<noteq> 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   781
    {assume "\<not> ?g > 1" hence ?thesis  using prems by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   782
    moreover
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   783
    {assume g1:"?g>1" hence g0: "?g > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   784
      from zgcd0 g1 nnz have gp0: "?g' \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   785
      hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   786
      hence "?g'= 1 \<or> ?g' > 1" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   787
      moreover {assume "?g'=1" hence ?thesis using prems 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   788
	  by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   789
      moreover {assume g'1:"?g'>1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   790
	have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   791
	have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   792
	have gpdgp: "?g' dvd ?g'" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   793
	from zdvd_imp_le[OF gpdd np] have g'n: "?g' \<le> n" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   794
	from zdiv_mono1[OF g'n g'p, simplified zdiv_self[OF gp0]]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   795
	have "n div ?g' >0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   796
	hence ?thesis using prems 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   797
	  by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0 simpnum_numbound0)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   798
      ultimately have ?thesis by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   799
    ultimately have ?thesis by blast} 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   800
  ultimately show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   801
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   802
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   803
consts simpfm :: "fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   804
recdef simpfm "measure fmsize"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   805
  "simpfm (And p q) = conj (simpfm p) (simpfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   806
  "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   807
  "simpfm (Imp p q) = imp (simpfm p) (simpfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   808
  "simpfm (Iff p q) = iff (simpfm p) (simpfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   809
  "simpfm (NOT p) = not (simpfm p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   810
  "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v < 0) then T else F 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   811
  | _ \<Rightarrow> Lt a')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   812
  "simpfm (Le a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<le> 0)  then T else F | _ \<Rightarrow> Le a')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   813
  "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v > 0)  then T else F | _ \<Rightarrow> Gt a')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   814
  "simpfm (Ge a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<ge> 0)  then T else F | _ \<Rightarrow> Ge a')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   815
  "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v = 0)  then T else F | _ \<Rightarrow> Eq a')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   816
  "simpfm (NEq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v \<noteq> 0)  then T else F | _ \<Rightarrow> NEq a')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   817
  "simpfm p = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   818
lemma simpfm: "Ifm bs (simpfm p) = Ifm bs p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   819
proof(induct p rule: simpfm.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   820
  case (6 a) let ?sa = "simpnum a" from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   821
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   822
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   823
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   824
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   825
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   826
  case (7 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   827
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   828
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   829
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   830
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   831
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   832
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   833
  case (8 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   834
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   835
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   836
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   837
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   838
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   839
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   840
  case (9 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   841
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   842
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   843
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   844
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   845
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   846
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   847
  case (10 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   848
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   849
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   850
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   851
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   852
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   853
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   854
  case (11 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   855
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   856
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   857
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   858
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   859
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   860
qed (induct p rule: simpfm.induct, simp_all add: conj disj imp iff not)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   861
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   862
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   863
lemma simpfm_bound0: "bound0 p \<Longrightarrow> bound0 (simpfm p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   864
proof(induct p rule: simpfm.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   865
  case (6 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   866
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   867
  thus ?case by (cases "simpnum a", auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   868
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   869
  case (7 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   870
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   871
  thus ?case by (cases "simpnum a", auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   872
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   873
  case (8 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   874
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   875
  thus ?case by (cases "simpnum a", auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   876
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   877
  case (9 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   878
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   879
  thus ?case by (cases "simpnum a", auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   880
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   881
  case (10 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   882
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   883
  thus ?case by (cases "simpnum a", auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   884
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   885
  case (11 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   886
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   887
  thus ?case by (cases "simpnum a", auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   888
qed(auto simp add: disj_def imp_def iff_def conj_def not_bn)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   889
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   890
lemma simpfm_qf: "qfree p \<Longrightarrow> qfree (simpfm p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   891
by (induct p rule: simpfm.induct, auto simp add: disj_qf imp_qf iff_qf conj_qf not_qf Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   892
 (case_tac "simpnum a",auto)+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   893
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   894
consts prep :: "fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   895
recdef prep "measure fmsize"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   896
  "prep (E T) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   897
  "prep (E F) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   898
  "prep (E (Or p q)) = disj (prep (E p)) (prep (E q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   899
  "prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   900
  "prep (E (Iff p q)) = disj (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   901
  "prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   902
  "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   903
  "prep (E (NOT (Iff p q))) = disj (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   904
  "prep (E p) = E (prep p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   905
  "prep (A (And p q)) = conj (prep (A p)) (prep (A q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   906
  "prep (A p) = prep (NOT (E (NOT p)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   907
  "prep (NOT (NOT p)) = prep p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   908
  "prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   909
  "prep (NOT (A p)) = prep (E (NOT p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   910
  "prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   911
  "prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   912
  "prep (NOT (Iff p q)) = disj (prep (And p (NOT q))) (prep (And (NOT p) q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   913
  "prep (NOT p) = not (prep p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   914
  "prep (Or p q) = disj (prep p) (prep q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   915
  "prep (And p q) = conj (prep p) (prep q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   916
  "prep (Imp p q) = prep (Or (NOT p) q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   917
  "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   918
  "prep p = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   919
(hints simp add: fmsize_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   920
lemma prep: "\<And> bs. Ifm bs (prep p) = Ifm bs p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   921
by (induct p rule: prep.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   922
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   923
  (* Generic quantifier elimination *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   924
consts qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   925
recdef qelim "measure fmsize"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   926
  "qelim (E p) = (\<lambda> qe. DJ qe (qelim p qe))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   927
  "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   928
  "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   929
  "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   930
  "qelim (Or  p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   931
  "qelim (Imp p q) = (\<lambda> qe. imp (qelim p qe) (qelim q qe))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   932
  "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   933
  "qelim p = (\<lambda> y. simpfm p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   934
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   935
lemma qelim_ci:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   936
  assumes qe_inv: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   937
  shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm bs (qelim p qe) = Ifm bs p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   938
using qe_inv DJ_qe[OF qe_inv] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   939
by(induct p rule: qelim.induct) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   940
(auto simp add: not disj conj iff imp not_qf disj_qf conj_qf imp_qf iff_qf 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   941
  simpfm simpfm_qf simp del: simpfm.simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   942
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   943
consts 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   944
  plusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of +\<infinity>*)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   945
  minusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of -\<infinity>*)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   946
recdef minusinf "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   947
  "minusinf (And p q) = conj (minusinf p) (minusinf q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   948
  "minusinf (Or p q) = disj (minusinf p) (minusinf q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   949
  "minusinf (Eq  (CN 0 c e)) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   950
  "minusinf (NEq (CN 0 c e)) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   951
  "minusinf (Lt  (CN 0 c e)) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   952
  "minusinf (Le  (CN 0 c e)) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   953
  "minusinf (Gt  (CN 0 c e)) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   954
  "minusinf (Ge  (CN 0 c e)) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   955
  "minusinf p = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   956
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   957
recdef plusinf "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   958
  "plusinf (And p q) = conj (plusinf p) (plusinf q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   959
  "plusinf (Or p q) = disj (plusinf p) (plusinf q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   960
  "plusinf (Eq  (CN 0 c e)) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   961
  "plusinf (NEq (CN 0 c e)) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   962
  "plusinf (Lt  (CN 0 c e)) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   963
  "plusinf (Le  (CN 0 c e)) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   964
  "plusinf (Gt  (CN 0 c e)) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   965
  "plusinf (Ge  (CN 0 c e)) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   966
  "plusinf p = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   967
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   968
consts
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   969
  isrlfm :: "fm \<Rightarrow> bool"   (* Linearity test for fm *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   970
recdef isrlfm "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   971
  "isrlfm (And p q) = (isrlfm p \<and> isrlfm q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   972
  "isrlfm (Or p q) = (isrlfm p \<and> isrlfm q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   973
  "isrlfm (Eq  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   974
  "isrlfm (NEq (CN 0 c e)) = (c>0 \<and> numbound0 e)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   975
  "isrlfm (Lt  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   976
  "isrlfm (Le  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   977
  "isrlfm (Gt  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   978
  "isrlfm (Ge  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   979
  "isrlfm p = (isatom p \<and> (bound0 p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   980
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   981
  (* splits the bounded from the unbounded part*)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   982
consts rsplit0 :: "num \<Rightarrow> int \<times> num" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   983
recdef rsplit0 "measure num_size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   984
  "rsplit0 (Bound 0) = (1,C 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   985
  "rsplit0 (Add a b) = (let (ca,ta) = rsplit0 a ; (cb,tb) = rsplit0 b 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   986
              in (ca+cb, Add ta tb))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   987
  "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   988
  "rsplit0 (Neg a) = (let (c,t) = rsplit0 a in (-c,Neg t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   989
  "rsplit0 (Mul c a) = (let (ca,ta) = rsplit0 a in (c*ca,Mul c ta))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   990
  "rsplit0 (CN 0 c a) = (let (ca,ta) = rsplit0 a in (c+ca,ta))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   991
  "rsplit0 (CN n c a) = (let (ca,ta) = rsplit0 a in (ca,CN n c ta))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   992
  "rsplit0 t = (0,t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   993
lemma rsplit0: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   994
  shows "Inum bs ((split (CN 0)) (rsplit0 t)) = Inum bs t \<and> numbound0 (snd (rsplit0 t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   995
proof (induct t rule: rsplit0.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   996
  case (2 a b) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   997
  let ?sa = "rsplit0 a" let ?sb = "rsplit0 b"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   998
  let ?ca = "fst ?sa" let ?cb = "fst ?sb"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   999
  let ?ta = "snd ?sa" let ?tb = "snd ?sb"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1000
  from prems have nb: "numbound0 (snd(rsplit0 (Add a b)))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1001
    by(cases "rsplit0 a",auto simp add: Let_def split_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1002
  have "Inum bs ((split (CN 0)) (rsplit0 (Add a b))) = 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1003
    Inum bs ((split (CN 0)) ?sa)+Inum bs ((split (CN 0)) ?sb)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1004
    by (simp add: Let_def split_def algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1005
  also have "\<dots> = Inum bs a + Inum bs b" using prems by (cases "rsplit0 a", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1006
  finally show ?case using nb by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1007
qed(auto simp add: Let_def split_def algebra_simps , simp add: right_distrib[symmetric])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1008
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1009
    (* Linearize a formula*)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1010
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1011
  lt :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1012
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1013
  "lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t)) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1014
    else (Gt (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1015
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1016
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1017
  le :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1018
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1019
  "le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t)) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1020
    else (Ge (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1021
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1022
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1023
  gt :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1024
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1025
  "gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t)) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1026
    else (Lt (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1027
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1028
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1029
  ge :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1030
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1031
  "ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t)) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1032
    else (Le (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1033
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1034
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1035
  eq :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1036
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1037
  "eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t)) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1038
    else (Eq (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1039
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1040
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1041
  neq :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1042
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1043
  "neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t)) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1044
    else (NEq (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1045
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1046
lemma lt: "numnoabs t \<Longrightarrow> Ifm bs (split lt (rsplit0 t)) = Ifm bs (Lt t) \<and> isrlfm (split lt (rsplit0 t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1047
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1048
by (auto simp add: lt_def split_def,cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1049
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1050
lemma le: "numnoabs t \<Longrightarrow> Ifm bs (split le (rsplit0 t)) = Ifm bs (Le t) \<and> isrlfm (split le (rsplit0 t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1051
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1052
by (auto simp add: le_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1053
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1054
lemma gt: "numnoabs t \<Longrightarrow> Ifm bs (split gt (rsplit0 t)) = Ifm bs (Gt t) \<and> isrlfm (split gt (rsplit0 t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1055
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1056
by (auto simp add: gt_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1057
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1058
lemma ge: "numnoabs t \<Longrightarrow> Ifm bs (split ge (rsplit0 t)) = Ifm bs (Ge t) \<and> isrlfm (split ge (rsplit0 t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1059
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1060
by (auto simp add: ge_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1061
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1062
lemma eq: "numnoabs t \<Longrightarrow> Ifm bs (split eq (rsplit0 t)) = Ifm bs (Eq t) \<and> isrlfm (split eq (rsplit0 t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1063
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1064
by (auto simp add: eq_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1065
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1066
lemma neq: "numnoabs t \<Longrightarrow> Ifm bs (split neq (rsplit0 t)) = Ifm bs (NEq t) \<and> isrlfm (split neq (rsplit0 t))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1067
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1068
by (auto simp add: neq_def split_def) (cases "snd(rsplit0 t)",auto,case_tac "nat",auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1069
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1070
lemma conj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (conj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1071
by (auto simp add: conj_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1072
lemma disj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (disj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1073
by (auto simp add: disj_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1074
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1075
consts rlfm :: "fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1076
recdef rlfm "measure fmsize"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1077
  "rlfm (And p q) = conj (rlfm p) (rlfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1078
  "rlfm (Or p q) = disj (rlfm p) (rlfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1079
  "rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1080
  "rlfm (Iff p q) = disj (conj (rlfm p) (rlfm q)) (conj (rlfm (NOT p)) (rlfm (NOT q)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1081
  "rlfm (Lt a) = split lt (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1082
  "rlfm (Le a) = split le (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1083
  "rlfm (Gt a) = split gt (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1084
  "rlfm (Ge a) = split ge (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1085
  "rlfm (Eq a) = split eq (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1086
  "rlfm (NEq a) = split neq (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1087
  "rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1088
  "rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1089
  "rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1090
  "rlfm (NOT (Iff p q)) = disj (conj(rlfm p) (rlfm(NOT q))) (conj(rlfm(NOT p)) (rlfm q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1091
  "rlfm (NOT (NOT p)) = rlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1092
  "rlfm (NOT T) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1093
  "rlfm (NOT F) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1094
  "rlfm (NOT (Lt a)) = rlfm (Ge a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1095
  "rlfm (NOT (Le a)) = rlfm (Gt a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1096
  "rlfm (NOT (Gt a)) = rlfm (Le a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1097
  "rlfm (NOT (Ge a)) = rlfm (Lt a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1098
  "rlfm (NOT (Eq a)) = rlfm (NEq a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1099
  "rlfm (NOT (NEq a)) = rlfm (Eq a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1100
  "rlfm p = p" (hints simp add: fmsize_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1101
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1102
lemma rlfm_I:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1103
  assumes qfp: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1104
  shows "(Ifm bs (rlfm p) = Ifm bs p) \<and> isrlfm (rlfm p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1105
  using qfp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1106
by (induct p rule: rlfm.induct, auto simp add: lt le gt ge eq neq conj disj conj_lin disj_lin)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1107
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1108
    (* Operations needed for Ferrante and Rackoff *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1109
lemma rminusinf_inf:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1110
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1111
  shows "\<exists> z. \<forall> x < z. Ifm (x#bs) (minusinf p) = Ifm (x#bs) p" (is "\<exists> z. \<forall> x. ?P z x p")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1112
using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1113
proof (induct p rule: minusinf.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1114
  case (1 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1115
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1116
  case (2 p q) thus ?case by (auto,rule_tac x= "min z za" in exI) auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1117
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1118
  case (3 c e) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1119
  from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1120
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1121
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1122
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1123
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1124
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1125
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1126
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1127
      by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1128
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1129
    hence "real c * x + ?e \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1130
    with xz have "?P ?z x (Eq (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1131
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp  }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1132
  hence "\<forall> x < ?z. ?P ?z x (Eq (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1133
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1134
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1135
  case (4 c e)   
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1136
  from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1137
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1138
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1139
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1140
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1141
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1142
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1143
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1144
      by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1145
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1146
    hence "real c * x + ?e \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1147
    with xz have "?P ?z x (NEq (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1148
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1149
  hence "\<forall> x < ?z. ?P ?z x (NEq (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1150
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1151
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1152
  case (5 c e) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1153
    from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1154
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1155
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1156
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1157
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1158
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1159
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1160
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1161
      by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1162
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1163
    with xz have "?P ?z x (Lt (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1164
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"]  by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1165
  hence "\<forall> x < ?z. ?P ?z x (Lt (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1166
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1167
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1168
  case (6 c e)  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1169
    from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1170
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1171
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1172
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1173
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1174
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1175
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1176
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1177
      by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1178
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1179
    with xz have "?P ?z x (Le (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1180
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1181
  hence "\<forall> x < ?z. ?P ?z x (Le (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1182
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1183
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1184
  case (7 c e)  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1185
    from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1186
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1187
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1188
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1189
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1190
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1191
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1192
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1193
      by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1194
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1195
    with xz have "?P ?z x (Gt (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1196
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1197
  hence "\<forall> x < ?z. ?P ?z x (Gt (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1198
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1199
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1200
  case (8 c e)  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1201
    from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1202
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1203
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1204
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1205
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1206
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1207
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1208
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1209
      by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="- ?e"] mult_ac) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1210
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1211
    with xz have "?P ?z x (Ge (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1212
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1213
  hence "\<forall> x < ?z. ?P ?z x (Ge (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1214
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1215
qed simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1216
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1217
lemma rplusinf_inf:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1218
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1219
  shows "\<exists> z. \<forall> x > z. Ifm (x#bs) (plusinf p) = Ifm (x#bs) p" (is "\<exists> z. \<forall> x. ?P z x p")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1220
using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1221
proof (induct p rule: isrlfm.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1222
  case (1 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1223
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1224
  case (2 p q) thus ?case by (auto,rule_tac x= "max z za" in exI) auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1225
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1226
  case (3 c e) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1227
  from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1228
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1229
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1230
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1231
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1232
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1233
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1234
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1235
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1236
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1237
    hence "real c * x + ?e \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1238
    with xz have "?P ?z x (Eq (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1239
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1240
  hence "\<forall> x > ?z. ?P ?z x (Eq (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1241
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1242
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1243
  case (4 c e) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1244
  from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1245
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1246
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1247
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1248
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1249
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1250
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1251
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1252
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1253
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1254
    hence "real c * x + ?e \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1255
    with xz have "?P ?z x (NEq (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1256
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1257
  hence "\<forall> x > ?z. ?P ?z x (NEq (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1258
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1259
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1260
  case (5 c e) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1261
  from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1262
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1263
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1264
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1265
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1266
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1267
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1268
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1269
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1270
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1271
    with xz have "?P ?z x (Lt (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1272
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1273
  hence "\<forall> x > ?z. ?P ?z x (Lt (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1274
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1275
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1276
  case (6 c e) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1277
  from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1278
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1279
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1280
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1281
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1282
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1283
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1284
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1285
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1286
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1287
    with xz have "?P ?z x (Le (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1288
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1289
  hence "\<forall> x > ?z. ?P ?z x (Le (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1290
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1291
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1292
  case (7 c e) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1293
  from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1294
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1295
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1296
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1297
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1298
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1299
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1300
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1301
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1302
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1303
    with xz have "?P ?z x (Gt (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1304
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"] by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1305
  hence "\<forall> x > ?z. ?P ?z x (Gt (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1306
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1307
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1308
  case (8 c e) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1309
  from prems have nb: "numbound0 e" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1310
  from prems have cp: "real c > 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1311
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1312
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1313
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1314
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1315
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1316
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1317
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1318
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1319
    with xz have "?P ?z x (Ge (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1320
      using numbound0_I[OF nb, where b="x" and bs="bs" and b'="a"]   by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1321
  hence "\<forall> x > ?z. ?P ?z x (Ge (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1322
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1323
qed simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1324
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1325
lemma rminusinf_bound0:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1326
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1327
  shows "bound0 (minusinf p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1328
  using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1329
  by (induct p rule: minusinf.induct) simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1330
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1331
lemma rplusinf_bound0:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1332
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1333
  shows "bound0 (plusinf p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1334
  using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1335
  by (induct p rule: plusinf.induct) simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1336
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1337
lemma rminusinf_ex:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1338
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1339
  and ex: "Ifm (a#bs) (minusinf p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1340
  shows "\<exists> x. Ifm (x#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1341
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1342
  from bound0_I [OF rminusinf_bound0[OF lp], where b="a" and bs ="bs"] ex
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1343
  have th: "\<forall> x. Ifm (x#bs) (minusinf p)" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1344
  from rminusinf_inf[OF lp, where bs="bs"] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1345
  obtain z where z_def: "\<forall>x<z. Ifm (x # bs) (minusinf p) = Ifm (x # bs) p" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1346
  from th have "Ifm ((z - 1)#bs) (minusinf p)" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1347
  moreover have "z - 1 < z" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1348
  ultimately show ?thesis using z_def by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1349
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1350
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1351
lemma rplusinf_ex:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1352
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1353
  and ex: "Ifm (a#bs) (plusinf p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1354
  shows "\<exists> x. Ifm (x#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1355
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1356
  from bound0_I [OF rplusinf_bound0[OF lp], where b="a" and bs ="bs"] ex
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1357
  have th: "\<forall> x. Ifm (x#bs) (plusinf p)" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1358
  from rplusinf_inf[OF lp, where bs="bs"] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1359
  obtain z where z_def: "\<forall>x>z. Ifm (x # bs) (plusinf p) = Ifm (x # bs) p" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1360
  from th have "Ifm ((z + 1)#bs) (plusinf p)" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1361
  moreover have "z + 1 > z" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1362
  ultimately show ?thesis using z_def by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1363
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1364
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1365
consts 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1366
  uset:: "fm \<Rightarrow> (num \<times> int) list"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1367
  usubst :: "fm \<Rightarrow> (num \<times> int) \<Rightarrow> fm "
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1368
recdef uset "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1369
  "uset (And p q) = (uset p @ uset q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1370
  "uset (Or p q) = (uset p @ uset q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1371
  "uset (Eq  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1372
  "uset (NEq (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1373
  "uset (Lt  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1374
  "uset (Le  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1375
  "uset (Gt  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1376
  "uset (Ge  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1377
  "uset p = []"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1378
recdef usubst "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1379
  "usubst (And p q) = (\<lambda> (t,n). And (usubst p (t,n)) (usubst q (t,n)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1380
  "usubst (Or p q) = (\<lambda> (t,n). Or (usubst p (t,n)) (usubst q (t,n)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1381
  "usubst (Eq (CN 0 c e)) = (\<lambda> (t,n). Eq (Add (Mul c t) (Mul n e)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1382
  "usubst (NEq (CN 0 c e)) = (\<lambda> (t,n). NEq (Add (Mul c t) (Mul n e)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1383
  "usubst (Lt (CN 0 c e)) = (\<lambda> (t,n). Lt (Add (Mul c t) (Mul n e)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1384
  "usubst (Le (CN 0 c e)) = (\<lambda> (t,n). Le (Add (Mul c t) (Mul n e)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1385
  "usubst (Gt (CN 0 c e)) = (\<lambda> (t,n). Gt (Add (Mul c t) (Mul n e)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1386
  "usubst (Ge (CN 0 c e)) = (\<lambda> (t,n). Ge (Add (Mul c t) (Mul n e)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1387
  "usubst p = (\<lambda> (t,n). p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1388
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1389
lemma usubst_I: assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1390
  and np: "real n > 0" and nbt: "numbound0 t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1391
  shows "(Ifm (x#bs) (usubst p (t,n)) = Ifm (((Inum (x#bs) t)/(real n))#bs) p) \<and> bound0 (usubst p (t,n))" (is "(?I x (usubst p (t,n)) = ?I ?u p) \<and> ?B p" is "(_ = ?I (?t/?n) p) \<and> _" is "(_ = ?I (?N x t /_) p) \<and> _")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1392
  using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1393
proof(induct p rule: usubst.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1394
  case (5 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1395
  have "?I ?u (Lt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) < 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1396
    using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1397
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) < 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1398
    by (simp only: pos_less_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1399
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1400
  also have "\<dots> = (real c *?t + ?n* (?N x e) < 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1401
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1402
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1403
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1404
  case (6 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1405
  have "?I ?u (Le (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<le> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1406
    using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1407
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<le> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1408
    by (simp only: pos_le_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1409
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1410
  also have "\<dots> = (real c *?t + ?n* (?N x e) \<le> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1411
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1412
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1413
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1414
  case (7 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1415
  have "?I ?u (Gt (CN 0 c e)) = (real c *(?t/?n) + (?N x e) > 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1416
    using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1417
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) > 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1418
    by (simp only: pos_divide_less_eq[OF np, where a="real c *(?t/?n) + (?N x e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1419
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1420
  also have "\<dots> = (real c *?t + ?n* (?N x e) > 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1421
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1422
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1423
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1424
  case (8 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1425
  have "?I ?u (Ge (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<ge> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1426
    using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1427
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<ge> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1428
    by (simp only: pos_divide_le_eq[OF np, where a="real c *(?t/?n) + (?N x e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1429
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1430
  also have "\<dots> = (real c *?t + ?n* (?N x e) \<ge> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1431
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1432
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1433
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1434
  case (3 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1435
  from np have np: "real n \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1436
  have "?I ?u (Eq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) = 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1437
    using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1438
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) = 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1439
    by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1440
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1441
  also have "\<dots> = (real c *?t + ?n* (?N x e) = 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1442
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1443
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1444
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1445
  case (4 c e) from prems have cp: "c >0" and nb: "numbound0 e" by simp+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1446
  from np have np: "real n \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1447
  have "?I ?u (NEq (CN 0 c e)) = (real c *(?t/?n) + (?N x e) \<noteq> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1448
    using numbound0_I[OF nb, where bs="bs" and b="?u" and b'="x"] by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1449
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<noteq> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1450
    by (simp only: nonzero_eq_divide_eq[OF np, where a="real c *(?t/?n) + (?N x e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1451
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1452
  also have "\<dots> = (real c *?t + ?n* (?N x e) \<noteq> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1453
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1454
  finally show ?case using nbt nb by (simp add: algebra_simps)