src/HOL/Decision_Procs/Ferrack.thy
author wenzelm
Mon, 03 Sep 2012 09:15:58 +0200
changeset 49070 f00fee6d21d4
parent 48891 c0eafbd55de3
child 49962 a8cc904a6820
permissions -rw-r--r--
tuned proofs;
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
41849
1a65b780bd56 Some cleaning up
nipkow
parents: 41842
diff changeset
     6
imports Complex_Main Dense_Linear_Order DP_Library
44013
5cfc1c36ae97 moved recdef package to HOL/Library/Old_Recdef.thy
krauss
parents: 42361
diff changeset
     7
  "~~/src/HOL/Library/Efficient_Nat" "~~/src/HOL/Library/Old_Recdef"
29789
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
  (****                            SHADOW SYNTAX AND SEMANTICS                  ****)
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
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
    17
  | Mul int num 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    18
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    19
  (* A size for num to make inductive proofs simpler*)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    20
primrec num_size :: "num \<Rightarrow> nat" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    21
  "num_size (C c) = 1"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    22
| "num_size (Bound n) = 1"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    23
| "num_size (Neg a) = 1 + num_size a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    24
| "num_size (Add a b) = 1 + num_size a + num_size b"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    25
| "num_size (Sub a b) = 3 + num_size a + num_size b"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    26
| "num_size (Mul c a) = 1 + num_size a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    27
| "num_size (CN n c a) = 3 + num_size a "
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    28
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    29
  (* Semantics of numeral terms (num) *)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    30
primrec Inum :: "real list \<Rightarrow> num \<Rightarrow> real" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    31
  "Inum bs (C c) = (real c)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    32
| "Inum bs (Bound n) = bs!n"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    33
| "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    34
| "Inum bs (Neg a) = -(Inum bs a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    35
| "Inum bs (Add a b) = Inum bs a + Inum bs b"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    36
| "Inum bs (Sub a b) = Inum bs a - Inum bs b"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    37
| "Inum bs (Mul c a) = (real c) * Inum bs a"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    38
    (* FORMULAE *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    39
datatype fm  = 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    40
  T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num|
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    41
  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
    42
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    43
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    44
  (* A size for fm *)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    45
fun fmsize :: "fm \<Rightarrow> nat" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    46
  "fmsize (NOT p) = 1 + fmsize p"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    47
| "fmsize (And p q) = 1 + fmsize p + fmsize q"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    48
| "fmsize (Or p q) = 1 + fmsize p + fmsize q"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    49
| "fmsize (Imp p q) = 3 + fmsize p + fmsize q"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    50
| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    51
| "fmsize (E p) = 1 + fmsize p"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    52
| "fmsize (A p) = 4+ fmsize p"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    53
| "fmsize p = 1"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    54
  (* several lemmas about fmsize *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    55
lemma fmsize_pos: "fmsize p > 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    56
by (induct p rule: fmsize.induct) simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    57
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    58
  (* Semantics of formulae (fm) *)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    59
primrec Ifm ::"real list \<Rightarrow> fm \<Rightarrow> bool" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    60
  "Ifm bs T = True"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    61
| "Ifm bs F = False"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    62
| "Ifm bs (Lt a) = (Inum bs a < 0)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    63
| "Ifm bs (Gt a) = (Inum bs a > 0)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    64
| "Ifm bs (Le a) = (Inum bs a \<le> 0)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    65
| "Ifm bs (Ge a) = (Inum bs a \<ge> 0)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    66
| "Ifm bs (Eq a) = (Inum bs a = 0)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    67
| "Ifm bs (NEq a) = (Inum bs a \<noteq> 0)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    68
| "Ifm bs (NOT p) = (\<not> (Ifm bs p))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    69
| "Ifm bs (And p q) = (Ifm bs p \<and> Ifm bs q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    70
| "Ifm bs (Or p q) = (Ifm bs p \<or> Ifm bs q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    71
| "Ifm bs (Imp p q) = ((Ifm bs p) \<longrightarrow> (Ifm bs q))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    72
| "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    73
| "Ifm bs (E p) = (\<exists> x. Ifm (x#bs) p)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
    74
| "Ifm bs (A p) = (\<forall> x. Ifm (x#bs) p)"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    75
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    76
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
    77
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    78
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    79
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    80
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
    81
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    82
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    83
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
    84
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    85
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    86
lemma IfmNOT: " (Ifm bs p = P) \<Longrightarrow> (Ifm bs (NOT p) = (\<not>P))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    87
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    88
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    89
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
    90
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    91
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    92
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
    93
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    94
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    95
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
    96
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    97
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
    98
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
    99
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   100
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   101
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   102
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
   103
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   104
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   105
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
   106
apply simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   107
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   108
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   109
fun not:: "fm \<Rightarrow> fm" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   110
  "not (NOT p) = p"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   111
| "not T = F"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   112
| "not F = T"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   113
| "not p = NOT p"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   114
lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   115
by (cases p) auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   116
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   117
definition conj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   118
  "conj p q = (if (p = F \<or> q=F) then F else if p=T then q else if q=T then p else 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   119
   if p = q then p else And p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   120
lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   121
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
   122
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   123
definition disj :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   124
  "disj p q = (if (p = T \<or> q=T) then T else if p=F then q else if q=F then p 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   125
       else if p=q then p else Or p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   126
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   127
lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   128
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
   129
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   130
definition imp :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   131
  "imp p q = (if (p = F \<or> q=T \<or> p=q) then T else if p=T then q else if q=F then not p 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   132
    else Imp p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   133
lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   134
by (cases "p=F \<or> q=T",simp_all add: imp_def) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   135
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   136
definition iff :: "fm \<Rightarrow> fm \<Rightarrow> fm" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   137
  "iff p q = (if (p = q) then T else if (p = NOT q \<or> NOT p = q) then F else 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   138
       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
   139
  Iff p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   140
lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   141
  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
   142
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   143
lemma conj_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   144
  "conj F Q = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   145
  "conj P F = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   146
  "conj T Q = Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   147
  "conj P T = P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   148
  "conj P P = P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   149
  "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
   150
  by (simp_all add: conj_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   151
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   152
lemma disj_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   153
  "disj T Q = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   154
  "disj P T = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   155
  "disj F Q = Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   156
  "disj P F = P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   157
  "disj P P = P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   158
  "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
   159
  by (simp_all add: disj_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   160
lemma imp_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   161
  "imp F Q = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   162
  "imp P T = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   163
  "imp T Q = Q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   164
  "imp P F = not P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   165
  "imp P P = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   166
  "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
   167
  by (simp_all add: imp_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   168
lemma trivNOT: "p \<noteq> NOT p" "NOT p \<noteq> p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   169
apply (induct p, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   170
done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   171
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   172
lemma iff_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   173
  "iff p p = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   174
  "iff p (NOT p) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   175
  "iff (NOT p) p = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   176
  "iff p F = not p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   177
  "iff F p = not p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   178
  "p \<noteq> NOT T \<Longrightarrow> iff T p = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   179
  "p\<noteq> NOT T \<Longrightarrow> iff p T = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   180
  "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
   181
  using trivNOT
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   182
  by (simp_all add: iff_def, cases p, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   183
  (* Quantifier freeness *)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   184
fun qfree:: "fm \<Rightarrow> bool" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   185
  "qfree (E p) = False"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   186
| "qfree (A p) = False"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   187
| "qfree (NOT p) = qfree p" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   188
| "qfree (And p q) = (qfree p \<and> qfree q)" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   189
| "qfree (Or  p q) = (qfree p \<and> qfree q)" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   190
| "qfree (Imp p q) = (qfree p \<and> qfree q)" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   191
| "qfree (Iff p q) = (qfree p \<and> qfree q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   192
| "qfree p = True"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   193
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   194
  (* Boundedness and substitution *)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   195
primrec numbound0:: "num \<Rightarrow> bool" (* a num is INDEPENDENT of Bound 0 *) where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   196
  "numbound0 (C c) = True"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   197
| "numbound0 (Bound n) = (n>0)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   198
| "numbound0 (CN n c a) = (n\<noteq>0 \<and> numbound0 a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   199
| "numbound0 (Neg a) = numbound0 a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   200
| "numbound0 (Add a b) = (numbound0 a \<and> numbound0 b)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   201
| "numbound0 (Sub a b) = (numbound0 a \<and> numbound0 b)" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   202
| "numbound0 (Mul i a) = numbound0 a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   203
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   204
lemma numbound0_I:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   205
  assumes nb: "numbound0 a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   206
  shows "Inum (b#bs) a = Inum (b'#bs) a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   207
using nb
41842
d8f76db6a207 added simp lemma nth_Cons_pos to List
nipkow
parents: 41838
diff changeset
   208
by (induct a) simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   209
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   210
primrec bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *) where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   211
  "bound0 T = True"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   212
| "bound0 F = True"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   213
| "bound0 (Lt a) = numbound0 a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   214
| "bound0 (Le a) = numbound0 a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   215
| "bound0 (Gt a) = numbound0 a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   216
| "bound0 (Ge a) = numbound0 a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   217
| "bound0 (Eq a) = numbound0 a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   218
| "bound0 (NEq a) = numbound0 a"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   219
| "bound0 (NOT p) = bound0 p"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   220
| "bound0 (And p q) = (bound0 p \<and> bound0 q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   221
| "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   222
| "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   223
| "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   224
| "bound0 (E p) = False"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   225
| "bound0 (A p) = False"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   226
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   227
lemma bound0_I:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   228
  assumes bp: "bound0 p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   229
  shows "Ifm (b#bs) p = Ifm (b'#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   230
using bp numbound0_I[where b="b" and bs="bs" and b'="b'"]
41842
d8f76db6a207 added simp lemma nth_Cons_pos to List
nipkow
parents: 41838
diff changeset
   231
by (induct p) auto
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   232
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   233
lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   234
by (cases p, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   235
lemma not_bn[simp]: "bound0 p \<Longrightarrow> bound0 (not p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   236
by (cases p, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   237
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   238
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   239
lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   240
using conj_def by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   241
lemma conj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   242
using conj_def by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   243
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   244
lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   245
using disj_def by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   246
lemma disj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   247
using disj_def by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   248
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   249
lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   250
using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   251
lemma imp_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   252
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
   253
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   254
lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   255
  by (unfold iff_def,cases "p=q", auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   256
lemma iff_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   257
using iff_def by (unfold iff_def,cases "p=q", auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   258
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   259
fun decrnum:: "num \<Rightarrow> num"  where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   260
  "decrnum (Bound n) = Bound (n - 1)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   261
| "decrnum (Neg a) = Neg (decrnum a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   262
| "decrnum (Add a b) = Add (decrnum a) (decrnum b)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   263
| "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   264
| "decrnum (Mul c a) = Mul c (decrnum a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   265
| "decrnum (CN n c a) = CN (n - 1) c (decrnum a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   266
| "decrnum a = a"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   267
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   268
fun decr :: "fm \<Rightarrow> fm" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   269
  "decr (Lt a) = Lt (decrnum a)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   270
| "decr (Le a) = Le (decrnum a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   271
| "decr (Gt a) = Gt (decrnum a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   272
| "decr (Ge a) = Ge (decrnum a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   273
| "decr (Eq a) = Eq (decrnum a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   274
| "decr (NEq a) = NEq (decrnum a)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   275
| "decr (NOT p) = NOT (decr p)" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   276
| "decr (And p q) = conj (decr p) (decr q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   277
| "decr (Or p q) = disj (decr p) (decr q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   278
| "decr (Imp p q) = imp (decr p) (decr q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   279
| "decr (Iff p q) = iff (decr p) (decr q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   280
| "decr p = p"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   281
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   282
lemma decrnum: assumes nb: "numbound0 t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   283
  shows "Inum (x#bs) t = Inum bs (decrnum t)"
41842
d8f76db6a207 added simp lemma nth_Cons_pos to List
nipkow
parents: 41838
diff changeset
   284
  using nb by (induct t rule: decrnum.induct, simp_all)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   285
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   286
lemma decr: assumes nb: "bound0 p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   287
  shows "Ifm (x#bs) p = Ifm bs (decr p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   288
  using nb 
41842
d8f76db6a207 added simp lemma nth_Cons_pos to List
nipkow
parents: 41838
diff changeset
   289
  by (induct p rule: decr.induct, simp_all add: decrnum)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   290
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   291
lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   292
by (induct p, simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   293
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   294
fun isatom :: "fm \<Rightarrow> bool" (* test for atomicity *) where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   295
  "isatom T = True"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   296
| "isatom F = True"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   297
| "isatom (Lt a) = True"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   298
| "isatom (Le a) = True"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   299
| "isatom (Gt a) = True"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   300
| "isatom (Ge a) = True"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   301
| "isatom (Eq a) = True"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   302
| "isatom (NEq a) = True"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   303
| "isatom p = False"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   304
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   305
lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   306
by (induct p, simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   307
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   308
definition djf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   309
  "djf f p q = (if q=T then T else if q=F then f p else 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   310
  (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or (f p) q))"
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   311
definition evaldjf :: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   312
  "evaldjf f ps = foldr (djf f) ps F"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   313
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   314
lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   315
by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   316
(cases "f p", simp_all add: Let_def djf_def) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   317
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   318
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   319
lemma djf_simps:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   320
  "djf f p T = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   321
  "djf f p F = f p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   322
  "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
   323
  by (simp_all add: djf_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   324
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   325
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
   326
  by(induct ps, simp_all add: evaldjf_def djf_Or)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   327
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   328
lemma evaldjf_bound0: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   329
  assumes nb: "\<forall> x\<in> set xs. bound0 (f x)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   330
  shows "bound0 (evaldjf f xs)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   331
  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
   332
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   333
lemma evaldjf_qf: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   334
  assumes nb: "\<forall> x\<in> set xs. qfree (f x)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   335
  shows "qfree (evaldjf f xs)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   336
  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
   337
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   338
fun disjuncts :: "fm \<Rightarrow> fm list" where
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   339
  "disjuncts (Or p q) = disjuncts p @ disjuncts q"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   340
| "disjuncts F = []"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   341
| "disjuncts p = [p]"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   342
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   343
lemma disjuncts: "(\<exists> q\<in> set (disjuncts p). Ifm bs q) = Ifm bs p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   344
by(induct p rule: disjuncts.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   345
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   346
lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). bound0 q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   347
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   348
  assume nb: "bound0 p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   349
  hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   350
  thus ?thesis by (simp only: list_all_iff)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   351
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   352
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   353
lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   354
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   355
  assume qf: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   356
  hence "list_all qfree (disjuncts p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   357
    by (induct p rule: disjuncts.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   358
  thus ?thesis by (simp only: list_all_iff)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   359
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   360
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   361
definition DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   362
  "DJ f p = evaldjf f (disjuncts p)"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   363
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   364
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
   365
  and fF: "f F = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   366
  shows "Ifm bs (DJ f p) = Ifm bs (f p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   367
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   368
  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
   369
    by (simp add: DJ_def evaldjf_ex) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   370
  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
   371
  finally show ?thesis .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   372
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   373
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   374
lemma DJ_qf: assumes 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   375
  fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   376
  shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   377
proof(clarify)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   378
  fix  p assume qf: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   379
  have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   380
  from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   381
  with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   382
  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   383
  from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   384
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   385
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   386
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
   387
  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
   388
proof(clarify)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   389
  fix p::fm and bs
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   390
  assume qf: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   391
  from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   392
  from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   393
  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
   394
    by (simp add: DJ_def evaldjf_ex)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   395
  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
   396
  also have "\<dots> = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   397
  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
   398
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   399
  (* Simplification *)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   400
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   401
fun maxcoeff:: "num \<Rightarrow> int" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   402
  "maxcoeff (C i) = abs i"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   403
| "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   404
| "maxcoeff t = 1"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   405
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   406
lemma maxcoeff_pos: "maxcoeff t \<ge> 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   407
  by (induct t rule: maxcoeff.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   408
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   409
fun numgcdh:: "num \<Rightarrow> int \<Rightarrow> int" where
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   410
  "numgcdh (C i) = (\<lambda>g. gcd i g)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   411
| "numgcdh (CN n c t) = (\<lambda>g. gcd c (numgcdh t g))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   412
| "numgcdh t = (\<lambda>g. 1)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   413
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   414
definition numgcd :: "num \<Rightarrow> int" where
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   415
  "numgcd t = numgcdh t (maxcoeff t)"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   416
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   417
fun reducecoeffh:: "num \<Rightarrow> int \<Rightarrow> num" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   418
  "reducecoeffh (C i) = (\<lambda> g. C (i div g))"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   419
| "reducecoeffh (CN n c t) = (\<lambda> g. CN n (c div g) (reducecoeffh t g))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   420
| "reducecoeffh t = (\<lambda>g. t)"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   421
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   422
definition reducecoeff :: "num \<Rightarrow> num" where
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   423
  "reducecoeff t =
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   424
  (let g = numgcd t in 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   425
  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
   426
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   427
fun dvdnumcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   428
  "dvdnumcoeff (C i) = (\<lambda> g. g dvd i)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   429
| "dvdnumcoeff (CN n c t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   430
| "dvdnumcoeff t = (\<lambda>g. False)"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   431
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   432
lemma dvdnumcoeff_trans: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   433
  assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   434
  shows "dvdnumcoeff t g"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   435
  using dgt' gdg 
30042
31039ee583fa Removed subsumed lemmas
nipkow
parents: 29823
diff changeset
   436
  by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg dvd_trans[OF gdg])
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   437
30042
31039ee583fa Removed subsumed lemmas
nipkow
parents: 29823
diff changeset
   438
declare dvd_trans [trans add]
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   439
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   440
lemma natabs0: "(nat (abs x) = 0) = (x = 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   441
by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   442
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   443
lemma numgcd0:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   444
  assumes g0: "numgcd t = 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   445
  shows "Inum bs t = 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   446
  using g0[simplified numgcd_def] 
32642
026e7c6a6d08 be more cautious wrt. simp rules: inf_absorb1, inf_absorb2, sup_absorb1, sup_absorb2 are no simp rules by default any longer
haftmann
parents: 32441
diff changeset
   447
  by (induct t rule: numgcdh.induct, auto simp add: natabs0 maxcoeff_pos min_max.sup_absorb2)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   448
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   449
lemma numgcdh_pos: assumes gp: "g \<ge> 0" shows "numgcdh t g \<ge> 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   450
  using gp
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   451
  by (induct t rule: numgcdh.induct, auto)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   452
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   453
lemma numgcd_pos: "numgcd t \<ge>0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   454
  by (simp add: numgcd_def numgcdh_pos maxcoeff_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   455
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   456
lemma reducecoeffh:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   457
  assumes gt: "dvdnumcoeff t g" and gp: "g > 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   458
  shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   459
  using gt
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   460
proof (induct t rule: reducecoeffh.induct) 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   461
  case (1 i)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   462
  hence gd: "g dvd i" by simp
46670
e9aa6d151329 removing unnecessary assumptions in RealDef;
bulwahn
parents: 45740
diff changeset
   463
  with assms show ?case by (simp add: real_of_int_div[OF gd])
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   464
next
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   465
  case (2 n c t)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   466
  hence gd: "g dvd c" by simp
46670
e9aa6d151329 removing unnecessary assumptions in RealDef;
bulwahn
parents: 45740
diff changeset
   467
  from assms 2 show ?case by (simp add: real_of_int_div[OF gd] algebra_simps)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   468
qed (auto simp add: numgcd_def gp)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   469
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   470
fun ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   471
  "ismaxcoeff (C i) = (\<lambda> x. abs i \<le> x)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   472
| "ismaxcoeff (CN n c t) = (\<lambda>x. abs c \<le> x \<and> (ismaxcoeff t x))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   473
| "ismaxcoeff t = (\<lambda>x. True)"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   474
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   475
lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'"
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   476
  by (induct t rule: ismaxcoeff.induct) auto
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   477
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   478
lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   479
proof (induct t rule: maxcoeff.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   480
  case (2 n c t)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   481
  hence H:"ismaxcoeff t (maxcoeff t)" .
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   482
  have thh: "maxcoeff t \<le> max (abs c) (maxcoeff t)" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   483
  from ismaxcoeff_mono[OF H thh] show ?case by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   484
qed simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   485
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   486
lemma zgcd_gt1: "gcd i j > (1::int) \<Longrightarrow> ((abs i > 1 \<and> abs j > 1) \<or> (abs i = 0 \<and> abs j > 1) \<or> (abs i > 1 \<and> abs j = 0))"
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   487
  apply (cases "abs i = 0", simp_all add: gcd_int_def)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   488
  apply (cases "abs j = 0", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   489
  apply (cases "abs i = 1", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   490
  apply (cases "abs j = 1", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   491
  apply auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   492
  done
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   493
lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow>  m =0"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   494
  by (induct t rule: numgcdh.induct, auto)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   495
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   496
lemma dvdnumcoeff_aux:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   497
  assumes "ismaxcoeff t m" and mp:"m \<ge> 0" and "numgcdh t m > 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   498
  shows "dvdnumcoeff t (numgcdh t m)"
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   499
using assms
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   500
proof(induct t rule: numgcdh.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   501
  case (2 n c t) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   502
  let ?g = "numgcdh t m"
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   503
  from 2 have th:"gcd c ?g > 1" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   504
  from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   505
  have "(abs c > 1 \<and> ?g > 1) \<or> (abs c = 0 \<and> ?g > 1) \<or> (abs c > 1 \<and> ?g = 0)" by simp
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   506
  moreover {assume "abs c > 1" and gp: "?g > 1" with 2
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   507
    have th: "dvdnumcoeff t ?g" by simp
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   508
    have th': "gcd c ?g dvd ?g" by simp
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   509
    from dvdnumcoeff_trans[OF th' th] have ?case by simp }
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   510
  moreover {assume "abs c = 0 \<and> ?g > 1"
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   511
    with 2 have th: "dvdnumcoeff t ?g" by simp
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   512
    have th': "gcd c ?g dvd ?g" by simp
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   513
    from dvdnumcoeff_trans[OF th' th] have ?case by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   514
    hence ?case by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   515
  moreover {assume "abs c > 1" and g0:"?g = 0" 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   516
    from numgcdh0[OF g0] have "m=0". with 2 g0 have ?case by simp }
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   517
  ultimately show ?case by blast
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   518
qed auto
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   519
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   520
lemma dvdnumcoeff_aux2:
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   521
  assumes "numgcd t > 1"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   522
  shows "dvdnumcoeff t (numgcd t) \<and> numgcd t > 0"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   523
  using assms
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   524
proof (simp add: numgcd_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   525
  let ?mc = "maxcoeff t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   526
  let ?g = "numgcdh t ?mc"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   527
  have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   528
  have th2: "?mc \<ge> 0" by (rule maxcoeff_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   529
  assume H: "numgcdh t ?mc > 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   530
  from dvdnumcoeff_aux[OF th1 th2 H]  show "dvdnumcoeff t ?g" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   531
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   532
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   533
lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   534
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   535
  let ?g = "numgcd t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   536
  have "?g \<ge> 0"  by (simp add: numgcd_pos)
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   537
  hence "?g = 0 \<or> ?g = 1 \<or> ?g > 1" by auto
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   538
  moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)} 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   539
  moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)} 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   540
  moreover { assume g1:"?g > 1"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   541
    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
   542
    from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   543
      by (simp add: reducecoeff_def Let_def)} 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   544
  ultimately show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   545
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   546
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   547
lemma reducecoeffh_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeffh t g)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   548
by (induct t rule: reducecoeffh.induct, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   549
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   550
lemma reducecoeff_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeff t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   551
using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   552
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   553
consts
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   554
  numadd:: "num \<times> num \<Rightarrow> num"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   555
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   556
recdef numadd "measure (\<lambda> (t,s). size t + size s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   557
  "numadd (CN n1 c1 r1,CN n2 c2 r2) =
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   558
  (if n1=n2 then 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   559
  (let c = c1 + c2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   560
  in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2))))
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   561
  else if n1 \<le> n2 then (CN n1 c1 (numadd (r1,CN n2 c2 r2))) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   562
  else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   563
  "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))"  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   564
  "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   565
  "numadd (C b1, C b2) = C (b1+b2)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   566
  "numadd (a,b) = Add a b"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   567
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   568
lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   569
apply (induct t s rule: numadd.induct, simp_all add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   570
apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   571
apply (case_tac "n1 = n2", simp_all add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   572
by (simp only: left_distrib[symmetric],simp)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   573
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   574
lemma numadd_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   575
by (induct t s rule: numadd.induct, auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   576
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   577
fun nummul:: "num \<Rightarrow> int \<Rightarrow> num" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   578
  "nummul (C j) = (\<lambda> i. C (i*j))"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   579
| "nummul (CN n c a) = (\<lambda> i. CN n (i*c) (nummul a i))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   580
| "nummul t = (\<lambda> i. Mul i t)"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   581
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   582
lemma nummul[simp]: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   583
by (induct t rule: nummul.induct, auto simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   584
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   585
lemma nummul_nb[simp]: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   586
by (induct t rule: nummul.induct, auto )
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   587
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   588
definition numneg :: "num \<Rightarrow> num" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   589
  "numneg t = nummul t (- 1)"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   590
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   591
definition numsub :: "num \<Rightarrow> num \<Rightarrow> num" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   592
  "numsub s t = (if s = t then C 0 else numadd (s,numneg t))"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   593
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   594
lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   595
using numneg_def by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   596
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   597
lemma numneg_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numneg t)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   598
using numneg_def by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   599
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   600
lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   601
using numsub_def by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   602
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   603
lemma numsub_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numsub t s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   604
using numsub_def by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   605
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   606
primrec simpnum:: "num \<Rightarrow> num" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   607
  "simpnum (C j) = C j"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   608
| "simpnum (Bound n) = CN n 1 (C 0)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   609
| "simpnum (Neg t) = numneg (simpnum t)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   610
| "simpnum (Add t s) = numadd (simpnum t,simpnum s)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   611
| "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   612
| "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   613
| "simpnum (CN n c t) = (if c = 0 then simpnum t else numadd (CN n c (C 0),simpnum t))"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   614
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   615
lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   616
by (induct t) simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   617
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   618
lemma simpnum_numbound0[simp]: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   619
  "numbound0 t \<Longrightarrow> numbound0 (simpnum t)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   620
by (induct t) simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   621
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   622
fun nozerocoeff:: "num \<Rightarrow> bool" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   623
  "nozerocoeff (C c) = True"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   624
| "nozerocoeff (CN n c t) = (c\<noteq>0 \<and> nozerocoeff t)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   625
| "nozerocoeff t = True"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   626
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   627
lemma numadd_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numadd (a,b))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   628
by (induct a b rule: numadd.induct,auto simp add: Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   629
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   630
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
   631
by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   632
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   633
lemma numneg_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff (numneg a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   634
by (simp add: numneg_def nummul_nz)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   635
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   636
lemma numsub_nz: "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numsub a b)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   637
by (simp add: numsub_def numneg_nz numadd_nz)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   638
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   639
lemma simpnum_nz: "nozerocoeff (simpnum t)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   640
by(induct t) (simp_all add: numadd_nz numneg_nz numsub_nz nummul_nz)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   641
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   642
lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   643
proof (induct t rule: maxcoeff.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   644
  case (2 n c t)
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   645
  hence cnz: "c \<noteq>0" and mx: "max (abs c) (maxcoeff t) = 0" by simp_all
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   646
  have "max (abs c) (maxcoeff t) \<ge> abs c" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   647
  with cnz have "max (abs c) (maxcoeff t) > 0" by arith
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   648
  with 2 show ?case by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   649
qed auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   650
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   651
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
   652
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   653
  from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   654
  from numgcdh0[OF th]  have th:"maxcoeff t = 0" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   655
  from maxcoeff_nz[OF nz th] show ?thesis .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   656
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   657
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
   658
definition simp_num_pair :: "(num \<times> int) \<Rightarrow> num \<times> int" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   659
  "simp_num_pair = (\<lambda> (t,n). (if n = 0 then (C 0, 0) else
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   660
   (let t' = simpnum t ; g = numgcd t' in 
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   661
      if g > 1 then (let g' = gcd n g in 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   662
        if g' = 1 then (t',n) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   663
        else (reducecoeffh t' g', n div g')) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   664
      else (t',n))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   665
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   666
lemma simp_num_pair_ci:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   667
  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
   668
  (is "?lhs = ?rhs")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   669
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   670
  let ?t' = "simpnum t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   671
  let ?g = "numgcd ?t'"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   672
  let ?g' = "gcd n ?g"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   673
  {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   674
  moreover
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   675
  { assume nnz: "n \<noteq> 0"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   676
    {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def) }
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   677
    moreover
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   678
    {assume g1:"?g>1" hence g0: "?g > 0" by simp
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   679
      from g1 nnz have gp0: "?g' \<noteq> 0" by simp
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31706
diff changeset
   680
      hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   681
      hence "?g'= 1 \<or> ?g' > 1" by arith
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   682
      moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   683
      moreover {assume g'1:"?g'>1"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   684
        from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" ..
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   685
        let ?tt = "reducecoeffh ?t' ?g'"
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   686
        let ?t = "Inum bs ?tt"
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   687
        have gpdg: "?g' dvd ?g" by simp
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   688
        have gpdd: "?g' dvd n" by simp 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   689
        have gpdgp: "?g' dvd ?g'" by simp
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   690
        from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   691
        have th2:"real ?g' * ?t = Inum bs ?t'" by simp
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   692
        from g1 g'1 have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def)
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   693
        also have "\<dots> = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   694
        also have "\<dots> = (Inum bs ?t' / real n)"
46670
e9aa6d151329 removing unnecessary assumptions in RealDef;
bulwahn
parents: 45740
diff changeset
   695
          using real_of_int_div[OF gpdd] th2 gp0 by simp
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   696
        finally have "?lhs = Inum bs t / real n" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   697
        then have ?thesis by (simp add: simp_num_pair_def) }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   698
      ultimately have ?thesis by blast }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   699
    ultimately have ?thesis by blast }
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   700
  ultimately show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   701
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   702
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   703
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
   704
  shows "numbound0 t' \<and> n' >0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   705
proof-
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   706
  let ?t' = "simpnum t"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   707
  let ?g = "numgcd ?t'"
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   708
  let ?g' = "gcd n ?g"
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   709
  { assume nz: "n = 0" hence ?thesis using assms by (simp add: Let_def simp_num_pair_def) }
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   710
  moreover
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   711
  { assume nnz: "n \<noteq> 0"
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   712
    { assume "\<not> ?g > 1" hence ?thesis using assms
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   713
        by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0) }
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   714
    moreover
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   715
    { assume g1:"?g>1" hence g0: "?g > 0" by simp
31706
1db0c8f235fb new GCD library, courtesy of Jeremy Avigad
huffman
parents: 30684
diff changeset
   716
      from g1 nnz have gp0: "?g' \<noteq> 0" by simp
31952
40501bb2d57c renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents: 31706
diff changeset
   717
      hence g'p: "?g' > 0" using gcd_ge_0_int[where x="n" and y="numgcd ?t'"] by arith
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   718
      hence "?g'= 1 \<or> ?g' > 1" by arith
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   719
      moreover {
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   720
        assume "?g' = 1" hence ?thesis using assms g1
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   721
          by (auto simp add: Let_def simp_num_pair_def simpnum_numbound0) }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   722
      moreover {
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   723
        assume g'1: "?g' > 1"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   724
        have gpdg: "?g' dvd ?g" by simp
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   725
        have gpdd: "?g' dvd n" by simp
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   726
        have gpdgp: "?g' dvd ?g'" by simp
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   727
        from zdvd_imp_le[OF gpdd np] have g'n: "?g' \<le> n" .
47142
d64fa2ca54b8 remove redundant lemmas
huffman
parents: 47108
diff changeset
   728
        from zdiv_mono1[OF g'n g'p, simplified div_self[OF gp0]]
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
   729
        have "n div ?g' >0" by simp
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   730
        hence ?thesis using assms g1 g'1
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   731
          by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0 simpnum_numbound0) }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   732
      ultimately have ?thesis by blast }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   733
    ultimately have ?thesis by blast }
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   734
  ultimately show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   735
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   736
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   737
fun simpfm :: "fm \<Rightarrow> fm" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   738
  "simpfm (And p q) = conj (simpfm p) (simpfm q)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   739
| "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   740
| "simpfm (Imp p q) = imp (simpfm p) (simpfm q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   741
| "simpfm (Iff p q) = iff (simpfm p) (simpfm q)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   742
| "simpfm (NOT p) = not (simpfm p)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   743
| "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v < 0) then T else F 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   744
  | _ \<Rightarrow> Lt a')"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   745
| "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')"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   746
| "simpfm (Gt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v > 0)  then T else F | _ \<Rightarrow> Gt a')"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   747
| "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')"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   748
| "simpfm (Eq a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v = 0)  then T else F | _ \<Rightarrow> Eq a')"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   749
| "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')"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   750
| "simpfm p = p"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   751
lemma simpfm: "Ifm bs (simpfm p) = Ifm bs p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   752
proof(induct p rule: simpfm.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   753
  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
   754
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   755
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   756
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   757
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   758
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   759
  case (7 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   760
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   761
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   762
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   763
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   764
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   765
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   766
  case (8 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   767
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   768
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   769
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   770
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   771
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   772
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   773
  case (9 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   774
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   775
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   776
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   777
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   778
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   779
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   780
  case (10 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   781
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   782
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   783
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   784
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   785
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   786
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   787
  case (11 a)  let ?sa = "simpnum a" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   788
  from simpnum_ci have sa: "Inum bs ?sa = Inum bs a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   789
  {fix v assume "?sa = C v" hence ?case using sa by simp }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   790
  moreover {assume "\<not> (\<exists> v. ?sa = C v)" hence ?case using sa 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   791
      by (cases ?sa, simp_all add: Let_def)}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   792
  ultimately show ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   793
qed (induct p rule: simpfm.induct, simp_all add: conj disj imp iff not)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   794
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   795
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   796
lemma simpfm_bound0: "bound0 p \<Longrightarrow> bound0 (simpfm p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   797
proof(induct p rule: simpfm.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   798
  case (6 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   799
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   800
  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   801
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   802
  case (7 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   803
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   804
  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   805
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   806
  case (8 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   807
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   808
  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   809
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   810
  case (9 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   811
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   812
  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   813
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   814
  case (10 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   815
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   816
  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   817
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   818
  case (11 a) hence nb: "numbound0 a" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   819
  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   820
  thus ?case by (cases "simpnum a") (auto simp add: Let_def)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   821
qed(auto simp add: disj_def imp_def iff_def conj_def not_bn)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   822
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   823
lemma simpfm_qf: "qfree p \<Longrightarrow> qfree (simpfm p)"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   824
  apply (induct p rule: simpfm.induct)
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   825
  apply (auto simp add: Let_def)
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   826
  apply (case_tac "simpnum a", auto)+
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   827
  done
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   828
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   829
consts prep :: "fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   830
recdef prep "measure fmsize"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   831
  "prep (E T) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   832
  "prep (E F) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   833
  "prep (E (Or p q)) = disj (prep (E p)) (prep (E q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   834
  "prep (E (Imp p q)) = disj (prep (E (NOT p))) (prep (E q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   835
  "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
   836
  "prep (E (NOT (And p q))) = disj (prep (E (NOT p))) (prep (E(NOT q)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   837
  "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   838
  "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
   839
  "prep (E p) = E (prep p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   840
  "prep (A (And p q)) = conj (prep (A p)) (prep (A q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   841
  "prep (A p) = prep (NOT (E (NOT p)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   842
  "prep (NOT (NOT p)) = prep p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   843
  "prep (NOT (And p q)) = disj (prep (NOT p)) (prep (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   844
  "prep (NOT (A p)) = prep (E (NOT p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   845
  "prep (NOT (Or p q)) = conj (prep (NOT p)) (prep (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   846
  "prep (NOT (Imp p q)) = conj (prep p) (prep (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   847
  "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
   848
  "prep (NOT p) = not (prep p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   849
  "prep (Or p q) = disj (prep p) (prep q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   850
  "prep (And p q) = conj (prep p) (prep q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   851
  "prep (Imp p q) = prep (Or (NOT p) q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   852
  "prep (Iff p q) = disj (prep (And p q)) (prep (And (NOT p) (NOT q)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   853
  "prep p = p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   854
(hints simp add: fmsize_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   855
lemma prep: "\<And> bs. Ifm bs (prep p) = Ifm bs p"
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
   856
  by (induct p rule: prep.induct) auto
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   857
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   858
  (* Generic quantifier elimination *)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   859
function (sequential) qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   860
  "qelim (E p) = (\<lambda> qe. DJ qe (qelim p qe))"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   861
| "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   862
| "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   863
| "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   864
| "qelim (Or  p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   865
| "qelim (Imp p q) = (\<lambda> qe. imp (qelim p qe) (qelim q qe))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   866
| "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   867
| "qelim p = (\<lambda> y. simpfm p)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   868
by pat_completeness auto
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   869
termination qelim by (relation "measure fmsize") simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   870
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   871
lemma qelim_ci:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   872
  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
   873
  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
   874
using qe_inv DJ_qe[OF qe_inv] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   875
by(induct p rule: qelim.induct) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   876
(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
   877
  simpfm simpfm_qf simp del: simpfm.simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   878
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   879
fun minusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of -\<infinity>*) where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   880
  "minusinf (And p q) = conj (minusinf p) (minusinf q)" 
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   881
| "minusinf (Or p q) = disj (minusinf p) (minusinf q)" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   882
| "minusinf (Eq  (CN 0 c e)) = F"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   883
| "minusinf (NEq (CN 0 c e)) = T"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   884
| "minusinf (Lt  (CN 0 c e)) = T"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   885
| "minusinf (Le  (CN 0 c e)) = T"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   886
| "minusinf (Gt  (CN 0 c e)) = F"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   887
| "minusinf (Ge  (CN 0 c e)) = F"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   888
| "minusinf p = p"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   889
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   890
fun plusinf:: "fm \<Rightarrow> fm" (* Virtual substitution of +\<infinity>*) where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   891
  "plusinf (And p q) = conj (plusinf p) (plusinf q)" 
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   892
| "plusinf (Or p q) = disj (plusinf p) (plusinf q)" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   893
| "plusinf (Eq  (CN 0 c e)) = F"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   894
| "plusinf (NEq (CN 0 c e)) = T"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   895
| "plusinf (Lt  (CN 0 c e)) = F"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   896
| "plusinf (Le  (CN 0 c e)) = F"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   897
| "plusinf (Gt  (CN 0 c e)) = T"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   898
| "plusinf (Ge  (CN 0 c e)) = T"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   899
| "plusinf p = p"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   900
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   901
fun isrlfm :: "fm \<Rightarrow> bool"   (* Linearity test for fm *) where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   902
  "isrlfm (And p q) = (isrlfm p \<and> isrlfm q)" 
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   903
| "isrlfm (Or p q) = (isrlfm p \<and> isrlfm q)" 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   904
| "isrlfm (Eq  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   905
| "isrlfm (NEq (CN 0 c e)) = (c>0 \<and> numbound0 e)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   906
| "isrlfm (Lt  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   907
| "isrlfm (Le  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   908
| "isrlfm (Gt  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   909
| "isrlfm (Ge  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   910
| "isrlfm p = (isatom p \<and> (bound0 p))"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   911
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   912
  (* splits the bounded from the unbounded part*)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   913
function (sequential) rsplit0 :: "num \<Rightarrow> int \<times> num" where
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   914
  "rsplit0 (Bound 0) = (1,C 0)"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   915
| "rsplit0 (Add a b) = (let (ca,ta) = rsplit0 a ; (cb,tb) = rsplit0 b 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   916
              in (ca+cb, Add ta tb))"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   917
| "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   918
| "rsplit0 (Neg a) = (let (c,t) = rsplit0 a in (-c,Neg t))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   919
| "rsplit0 (Mul c a) = (let (ca,ta) = rsplit0 a in (c*ca,Mul c ta))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   920
| "rsplit0 (CN 0 c a) = (let (ca,ta) = rsplit0 a in (c+ca,ta))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   921
| "rsplit0 (CN n c a) = (let (ca,ta) = rsplit0 a in (ca,CN n c ta))"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   922
| "rsplit0 t = (0,t)"
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   923
by pat_completeness auto
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   924
termination rsplit0 by (relation "measure num_size") simp_all
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   925
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   926
lemma rsplit0: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   927
  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
   928
proof (induct t rule: rsplit0.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   929
  case (2 a b) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   930
  let ?sa = "rsplit0 a" let ?sb = "rsplit0 b"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   931
  let ?ca = "fst ?sa" let ?cb = "fst ?sb"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   932
  let ?ta = "snd ?sa" let ?tb = "snd ?sb"
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   933
  from 2 have nb: "numbound0 (snd(rsplit0 (Add a b)))" 
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
   934
    by (cases "rsplit0 a") (auto simp add: Let_def split_def)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   935
  have "Inum bs ((split (CN 0)) (rsplit0 (Add a b))) = 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   936
    Inum bs ((split (CN 0)) ?sa)+Inum bs ((split (CN 0)) ?sb)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   937
    by (simp add: Let_def split_def algebra_simps)
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   938
  also have "\<dots> = Inum bs a + Inum bs b" using 2 by (cases "rsplit0 a") auto
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   939
  finally show ?case using nb by simp 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
   940
qed (auto simp add: Let_def split_def algebra_simps, simp add: right_distrib[symmetric])
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   941
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   942
    (* Linearize a formula*)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   943
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   944
  lt :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   945
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   946
  "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
   947
    else (Gt (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   948
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   949
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   950
  le :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   951
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   952
  "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
   953
    else (Ge (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   954
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   955
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   956
  gt :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   957
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   958
  "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
   959
    else (Lt (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   960
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   961
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   962
  ge :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   963
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   964
  "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
   965
    else (Le (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   966
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   967
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   968
  eq :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   969
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   970
  "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
   971
    else (Eq (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   972
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   973
definition
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   974
  neq :: "int \<Rightarrow> num \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   975
where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   976
  "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
   977
    else (NEq (CN 0 (-c) (Neg t))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   978
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   979
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
   980
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   981
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
   982
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   983
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
   984
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   985
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
   986
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   987
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
   988
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   989
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
   990
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   991
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
   992
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   993
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
   994
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   995
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
   996
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   997
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
   998
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
   999
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
  1000
using rsplit0[where bs = "bs" and t="t"]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1001
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
  1002
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1003
lemma conj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (conj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1004
by (auto simp add: conj_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1005
lemma disj_lin: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (disj p q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1006
by (auto simp add: disj_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1007
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1008
consts rlfm :: "fm \<Rightarrow> fm"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1009
recdef rlfm "measure fmsize"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1010
  "rlfm (And p q) = conj (rlfm p) (rlfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1011
  "rlfm (Or p q) = disj (rlfm p) (rlfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1012
  "rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1013
  "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
  1014
  "rlfm (Lt a) = split lt (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1015
  "rlfm (Le a) = split le (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1016
  "rlfm (Gt a) = split gt (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1017
  "rlfm (Ge a) = split ge (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1018
  "rlfm (Eq a) = split eq (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1019
  "rlfm (NEq a) = split neq (rsplit0 a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1020
  "rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1021
  "rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1022
  "rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1023
  "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
  1024
  "rlfm (NOT (NOT p)) = rlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1025
  "rlfm (NOT T) = F"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1026
  "rlfm (NOT F) = T"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1027
  "rlfm (NOT (Lt a)) = rlfm (Ge a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1028
  "rlfm (NOT (Le a)) = rlfm (Gt a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1029
  "rlfm (NOT (Gt a)) = rlfm (Le a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1030
  "rlfm (NOT (Ge a)) = rlfm (Lt a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1031
  "rlfm (NOT (Eq a)) = rlfm (NEq a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1032
  "rlfm (NOT (NEq a)) = rlfm (Eq a)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1033
  "rlfm p = p" (hints simp add: fmsize_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1034
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1035
lemma rlfm_I:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1036
  assumes qfp: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1037
  shows "(Ifm bs (rlfm p) = Ifm bs p) \<and> isrlfm (rlfm p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1038
  using qfp 
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
  1039
by (induct p rule: rlfm.induct) (auto simp add: lt le gt ge eq neq conj disj conj_lin disj_lin)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1040
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1041
    (* Operations needed for Ferrante and Rackoff *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1042
lemma rminusinf_inf:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1043
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1044
  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
  1045
using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1046
proof (induct p rule: minusinf.induct)
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
  1047
  case (1 p q)
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
  1048
  thus ?case apply auto apply (rule_tac x= "min z za" in exI) apply auto done
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1049
next
44779
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
  1050
  case (2 p q)
98d597c4193d tuned proofs;
wenzelm
parents: 44013
diff changeset
  1051
  thus ?case apply auto apply (rule_tac x= "min z za" in exI) apply auto done
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1052
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1053
  case (3 c e) 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1054
  from 3 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1055
  from 3 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1056
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1057
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1058
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1059
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1060
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1061
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1062
      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
  1063
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1064
    hence "real c * x + ?e \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1065
    with xz have "?P ?z x (Eq (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1066
      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
  1067
  hence "\<forall> x < ?z. ?P ?z x (Eq (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1068
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1069
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1070
  case (4 c e)   
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1071
  from 4 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1072
  from 4 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1073
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1074
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1075
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1076
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1077
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1078
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1079
      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
  1080
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1081
    hence "real c * x + ?e \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1082
    with xz have "?P ?z x (NEq (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1083
      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
  1084
  hence "\<forall> x < ?z. ?P ?z x (NEq (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1085
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1086
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1087
  case (5 c e) 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1088
  from 5 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1089
  from 5 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1090
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1091
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1092
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1093
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1094
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1095
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1096
      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
  1097
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1098
    with xz have "?P ?z x (Lt (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1099
      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
  1100
  hence "\<forall> x < ?z. ?P ?z x (Lt (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1101
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1102
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1103
  case (6 c e)  
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1104
  from 6 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1105
  from lp 6 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1106
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1107
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1108
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1109
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1110
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1111
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1112
      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
  1113
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1114
    with xz have "?P ?z x (Le (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1115
      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
  1116
  hence "\<forall> x < ?z. ?P ?z x (Le (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1117
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1118
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1119
  case (7 c e)  
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1120
  from 7 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1121
  from 7 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1122
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1123
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1124
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1125
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1126
    assume xz: "x < ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1127
    hence "(real c * x < - ?e)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1128
      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
  1129
    hence "real c * x + ?e < 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1130
    with xz have "?P ?z x (Gt (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 (Gt (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 (8 c e)  
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1136
  from 8 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1137
  from 8 have cp: "real c > 0" by simp
29789
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
    with xz have "?P ?z x (Ge (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1147
      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
  1148
  hence "\<forall> x < ?z. ?P ?z x (Ge (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1149
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1150
qed simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1151
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1152
lemma rplusinf_inf:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1153
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1154
  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
  1155
using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1156
proof (induct p rule: isrlfm.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1157
  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
  1158
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1159
  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
  1160
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1161
  case (3 c e) 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1162
  from 3 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1163
  from 3 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1164
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1165
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1166
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1167
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1168
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1169
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1170
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1171
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1172
    hence "real c * x + ?e \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1173
    with xz have "?P ?z x (Eq (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1174
      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
  1175
  hence "\<forall> x > ?z. ?P ?z x (Eq (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1176
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1177
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1178
  case (4 c e) 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1179
  from 4 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1180
  from 4 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1181
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1182
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1183
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1184
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1185
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1186
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1187
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1188
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1189
    hence "real c * x + ?e \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1190
    with xz have "?P ?z x (NEq (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1191
      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
  1192
  hence "\<forall> x > ?z. ?P ?z x (NEq (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1193
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1194
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1195
  case (5 c e) 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1196
  from 5 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1197
  from 5 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1198
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1199
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1200
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1201
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1202
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1203
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1204
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1205
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1206
    with xz have "?P ?z x (Lt (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1207
      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
  1208
  hence "\<forall> x > ?z. ?P ?z x (Lt (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1209
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1210
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1211
  case (6 c e) 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1212
  from 6 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1213
  from 6 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1214
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1215
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1216
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1217
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1218
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1219
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1220
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1221
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1222
    with xz have "?P ?z x (Le (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1223
      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
  1224
  hence "\<forall> x > ?z. ?P ?z x (Le (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1225
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1226
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1227
  case (7 c e) 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1228
  from 7 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1229
  from 7 have cp: "real c > 0" by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1230
  fix a
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1231
  let ?e="Inum (a#bs) e"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1232
  let ?z = "(- ?e) / real c"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1233
  {fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1234
    assume xz: "x > ?z"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1235
    with mult_strict_right_mono [OF xz cp] cp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1236
    have "(real c * x > - ?e)" by (simp add: mult_ac)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1237
    hence "real c * x + ?e > 0" by arith
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1238
    with xz have "?P ?z x (Gt (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 (Gt (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 (8 c e) 
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1244
  from 8 have nb: "numbound0 e" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1245
  from 8 have cp: "real c > 0" by simp
29789
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
    with xz have "?P ?z x (Ge (CN 0 c e))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1255
      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
  1256
  hence "\<forall> x > ?z. ?P ?z x (Ge (CN 0 c e))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1257
  thus ?case by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1258
qed simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1259
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1260
lemma rminusinf_bound0:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1261
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1262
  shows "bound0 (minusinf p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1263
  using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1264
  by (induct p rule: minusinf.induct) simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1265
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1266
lemma rplusinf_bound0:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1267
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1268
  shows "bound0 (plusinf p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1269
  using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1270
  by (induct p rule: plusinf.induct) simp_all
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1271
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1272
lemma rminusinf_ex:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1273
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1274
  and ex: "Ifm (a#bs) (minusinf p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1275
  shows "\<exists> x. Ifm (x#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1276
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1277
  from bound0_I [OF rminusinf_bound0[OF lp], where b="a" and bs ="bs"] ex
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1278
  have th: "\<forall> x. Ifm (x#bs) (minusinf p)" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1279
  from rminusinf_inf[OF lp, where bs="bs"] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1280
  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
  1281
  from th have "Ifm ((z - 1)#bs) (minusinf p)" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1282
  moreover have "z - 1 < z" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1283
  ultimately show ?thesis using z_def by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1284
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1285
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1286
lemma rplusinf_ex:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1287
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1288
  and ex: "Ifm (a#bs) (plusinf p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1289
  shows "\<exists> x. Ifm (x#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1290
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1291
  from bound0_I [OF rplusinf_bound0[OF lp], where b="a" and bs ="bs"] ex
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1292
  have th: "\<forall> x. Ifm (x#bs) (plusinf p)" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1293
  from rplusinf_inf[OF lp, where bs="bs"] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1294
  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
  1295
  from th have "Ifm ((z + 1)#bs) (plusinf p)" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1296
  moreover have "z + 1 > z" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1297
  ultimately show ?thesis using z_def by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1298
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1299
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1300
consts 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1301
  uset:: "fm \<Rightarrow> (num \<times> int) list"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1302
  usubst :: "fm \<Rightarrow> (num \<times> int) \<Rightarrow> fm "
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1303
recdef uset "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1304
  "uset (And p q) = (uset p @ uset q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1305
  "uset (Or p q) = (uset p @ uset q)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1306
  "uset (Eq  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1307
  "uset (NEq (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1308
  "uset (Lt  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1309
  "uset (Le  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1310
  "uset (Gt  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1311
  "uset (Ge  (CN 0 c e)) = [(Neg e,c)]"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1312
  "uset p = []"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1313
recdef usubst "measure size"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1314
  "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
  1315
  "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
  1316
  "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
  1317
  "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
  1318
  "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
  1319
  "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
  1320
  "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
  1321
  "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
  1322
  "usubst p = (\<lambda> (t,n). p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1323
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1324
lemma usubst_I: assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1325
  and np: "real n > 0" and nbt: "numbound0 t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1326
  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
  1327
  using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1328
proof(induct p rule: usubst.induct)
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1329
  case (5 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1330
  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
  1331
    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
  1332
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) < 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1333
    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
  1334
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1335
  also have "\<dots> = (real c *?t + ?n* (?N x e) < 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1336
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1337
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1338
next
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1339
  case (6 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1340
  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
  1341
    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
  1342
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<le> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1343
    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
  1344
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1345
  also have "\<dots> = (real c *?t + ?n* (?N x e) \<le> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1346
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1347
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1348
next
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1349
  case (7 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1350
  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
  1351
    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
  1352
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) > 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1353
    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
  1354
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1355
  also have "\<dots> = (real c *?t + ?n* (?N x e) > 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1356
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1357
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1358
next
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1359
  case (8 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1360
  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
  1361
    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
  1362
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<ge> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1363
    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
  1364
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1365
  also have "\<dots> = (real c *?t + ?n* (?N x e) \<ge> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1366
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1367
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1368
next
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1369
  case (3 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1370
  from np have np: "real n \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1371
  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
  1372
    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
  1373
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) = 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1374
    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
  1375
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1376
  also have "\<dots> = (real c *?t + ?n* (?N x e) = 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1377
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1378
  finally show ?case using nbt nb by (simp add: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1379
next
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1380
  case (4 c e) with assms have cp: "c >0" and nb: "numbound0 e" by simp_all
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1381
  from np have np: "real n \<noteq> 0" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1382
  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
  1383
    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
  1384
  also have "\<dots> = (?n*(real c *(?t/?n)) + ?n*(?N x e) \<noteq> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1385
    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
  1386
      and b="0", simplified divide_zero_left]) (simp only: algebra_simps)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1387
  also have "\<dots> = (real c *?t + ?n* (?N x e) \<noteq> 0)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1388
    using np by simp 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1389
  finally show ?case using nbt nb by (simp add: algebra_simps)
41842
d8f76db6a207 added simp lemma nth_Cons_pos to List
nipkow
parents: 41838
diff changeset
  1390
qed(simp_all add: nbt numbound0_I[where bs ="bs" and b="(Inum (x#bs) t)/ real n" and b'="x"])
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1391
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1392
lemma uset_l:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1393
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1394
  shows "\<forall> (t,k) \<in> set (uset p). numbound0 t \<and> k >0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1395
using lp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1396
by(induct p rule: uset.induct,auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1397
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1398
lemma rminusinf_uset:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1399
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1400
  and nmi: "\<not> (Ifm (a#bs) (minusinf p))" (is "\<not> (Ifm (a#bs) (?M p))")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1401
  and ex: "Ifm (x#bs) p" (is "?I x p")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1402
  shows "\<exists> (s,m) \<in> set (uset p). x \<ge> Inum (a#bs) s / real m" (is "\<exists> (s,m) \<in> ?U p. x \<ge> ?N a s / real m")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1403
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1404
  have "\<exists> (s,m) \<in> set (uset p). real m * x \<ge> Inum (a#bs) s " (is "\<exists> (s,m) \<in> ?U p. real m *x \<ge> ?N a s")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1405
    using lp nmi ex
41842
d8f76db6a207 added simp lemma nth_Cons_pos to List
nipkow
parents: 41838
diff changeset
  1406
    by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"])
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1407
  then obtain s m where smU: "(s,m) \<in> set (uset p)" and mx: "real m * x \<ge> ?N a s" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1408
  from uset_l[OF lp] smU have mp: "real m > 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1409
  from pos_divide_le_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \<ge> ?N a s / real m" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1410
    by (auto simp add: mult_commute)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1411
  thus ?thesis using smU by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1412
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1413
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1414
lemma rplusinf_uset:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1415
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1416
  and nmi: "\<not> (Ifm (a#bs) (plusinf p))" (is "\<not> (Ifm (a#bs) (?M p))")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1417
  and ex: "Ifm (x#bs) p" (is "?I x p")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1418
  shows "\<exists> (s,m) \<in> set (uset p). x \<le> Inum (a#bs) s / real m" (is "\<exists> (s,m) \<in> ?U p. x \<le> ?N a s / real m")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1419
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1420
  have "\<exists> (s,m) \<in> set (uset p). real m * x \<le> Inum (a#bs) s " (is "\<exists> (s,m) \<in> ?U p. real m *x \<le> ?N a s")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1421
    using lp nmi ex
41842
d8f76db6a207 added simp lemma nth_Cons_pos to List
nipkow
parents: 41838
diff changeset
  1422
    by (induct p rule: minusinf.induct, auto simp add:numbound0_I[where bs="bs" and b="a" and b'="x"])
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1423
  then obtain s m where smU: "(s,m) \<in> set (uset p)" and mx: "real m * x \<le> ?N a s" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1424
  from uset_l[OF lp] smU have mp: "real m > 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1425
  from pos_le_divide_eq[OF mp, where a="x" and b="?N a s", symmetric] mx have "x \<le> ?N a s / real m" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1426
    by (auto simp add: mult_commute)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1427
  thus ?thesis using smU by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1428
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1429
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1430
lemma lin_dense: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1431
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1432
  and noS: "\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> (\<lambda> (t,n). Inum (x#bs) t / real n) ` set (uset p)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1433
  (is "\<forall> t. _ \<and> _ \<longrightarrow> t \<notin> (\<lambda> (t,n). ?N x t / real n ) ` (?U p)")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1434
  and lx: "l < x" and xu:"x < u" and px:" Ifm (x#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1435
  and ly: "l < y" and yu: "y < u"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1436
  shows "Ifm (y#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1437
using lp px noS
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1438
proof (induct p rule: isrlfm.induct)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1439
  case (5 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1440
  from 5 have "x * real c + ?N x e < 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1441
  hence pxc: "x < (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1442
    by (simp only: pos_less_divide_eq[OF cp, where a="x" and b="-?N x e"])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1443
  from 5 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1444
  with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1445
  hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1446
  moreover {assume y: "y < (-?N x e)/ real c"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1447
    hence "y * real c < - ?N x e"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1448
      by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1449
    hence "real c * y + ?N x e < 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1450
    hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp}
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1451
  moreover {assume y: "y > (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1452
    with yu have eu: "u > (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1453
    with noSc ly yu have "(- ?N x e) / real c \<le> l" by (cases "(- ?N x e) / real c > l", auto)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1454
    with lx pxc have "False" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1455
    hence ?case by simp }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1456
  ultimately show ?case by blast
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1457
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1458
  case (6 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp +
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1459
  from 6 have "x * real c + ?N x e \<le> 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1460
  hence pxc: "x \<le> (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1461
    by (simp only: pos_le_divide_eq[OF cp, where a="x" and b="-?N x e"])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1462
  from 6 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1463
  with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1464
  hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1465
  moreover {assume y: "y < (-?N x e)/ real c"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1466
    hence "y * real c < - ?N x e"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1467
      by (simp add: pos_less_divide_eq[OF cp, where a="y" and b="-?N x e", symmetric])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1468
    hence "real c * y + ?N x e < 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1469
    hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp}
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1470
  moreover {assume y: "y > (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1471
    with yu have eu: "u > (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1472
    with noSc ly yu have "(- ?N x e) / real c \<le> l" by (cases "(- ?N x e) / real c > l", auto)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1473
    with lx pxc have "False" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1474
    hence ?case by simp }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1475
  ultimately show ?case by blast
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1476
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1477
  case (7 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1478
  from 7 have "x * real c + ?N x e > 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1479
  hence pxc: "x > (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1480
    by (simp only: pos_divide_less_eq[OF cp, where a="x" and b="-?N x e"])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1481
  from 7 have noSc: "\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1482
  with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1483
  hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1484
  moreover {assume y: "y > (-?N x e)/ real c"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1485
    hence "y * real c > - ?N x e"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1486
      by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1487
    hence "real c * y + ?N x e > 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1488
    hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp}
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1489
  moreover {assume y: "y < (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1490
    with ly have eu: "l < (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1491
    with noSc ly yu have "(- ?N x e) / real c \<ge> u" by (cases "(- ?N x e) / real c > l", auto)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1492
    with xu pxc have "False" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1493
    hence ?case by simp }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1494
  ultimately show ?case by blast
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1495
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1496
  case (8 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1497
  from 8 have "x * real c + ?N x e \<ge> 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1498
  hence pxc: "x \<ge> (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1499
    by (simp only: pos_divide_le_eq[OF cp, where a="x" and b="-?N x e"])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1500
  from 8 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1501
  with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1502
  hence "y < (- ?N x e) / real c \<or> y > (-?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1503
  moreover {assume y: "y > (-?N x e)/ real c"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1504
    hence "y * real c > - ?N x e"
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1505
      by (simp add: pos_divide_less_eq[OF cp, where a="y" and b="-?N x e", symmetric])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1506
    hence "real c * y + ?N x e > 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1507
    hence ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] by simp}
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1508
  moreover {assume y: "y < (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1509
    with ly have eu: "l < (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1510
    with noSc ly yu have "(- ?N x e) / real c \<ge> u" by (cases "(- ?N x e) / real c > l", auto)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1511
    with xu pxc have "False" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1512
    hence ?case by simp }
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1513
  ultimately show ?case by blast
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1514
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1515
  case (3 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1516
  from cp have cnz: "real c \<noteq> 0" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1517
  from 3 have "x * real c + ?N x e = 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1518
  hence pxc: "x = (- ?N x e) / real c" 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1519
    by (simp only: nonzero_eq_divide_eq[OF cnz, where a="x" and b="-?N x e"])
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1520
  from 3 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1521
  with lx xu have yne: "x \<noteq> - ?N x e / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1522
  with pxc show ?case by simp
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1523
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1524
  case (4 c e) hence cp: "real c > 0" and nb: "numbound0 e" by simp+
41807
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1525
  from cp have cnz: "real c \<noteq> 0" by simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1526
  from 4 have noSc:"\<forall> t. l < t \<and> t < u \<longrightarrow> t \<noteq> (- ?N x e) / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1527
  with ly yu have yne: "y \<noteq> - ?N x e / real c" by auto
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1528
  hence "y* real c \<noteq> -?N x e"      
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1529
    by (simp only: nonzero_eq_divide_eq[OF cnz, where a="y" and b="-?N x e"]) simp
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1530
  hence "y* real c + ?N x e \<noteq> 0" by (simp add: algebra_simps)
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1531
  thus ?case using numbound0_I[OF nb, where bs="bs" and b="x" and b'="y"] 
ab5d2d81f9fb tuned proofs -- eliminated prems;
wenzelm
parents: 41413
diff changeset
  1532
    by (simp add: algebra_simps)
41842
d8f76db6a207 added simp lemma nth_Cons_pos to List
nipkow
parents: 41838
diff changeset
  1533
qed (auto simp add: numbound0_I[where bs="bs" and b="y" and b'="x"])
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1534
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1535
lemma finite_set_intervals:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1536
  assumes px: "P (x::real)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1537
  and lx: "l \<le> x" and xu: "x \<le> u"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1538
  and linS: "l\<in> S" and uinS: "u \<in> S"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1539
  and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1540
  shows "\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a < y \<and> y < b \<longrightarrow> y \<notin> S) \<and> a \<le> x \<and> x \<le> b \<and> P x"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1541
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1542
  let ?Mx = "{y. y\<in> S \<and> y \<le> x}"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1543
  let ?xM = "{y. y\<in> S \<and> x \<le> y}"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1544
  let ?a = "Max ?Mx"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1545
  let ?b = "Min ?xM"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1546
  have MxS: "?Mx \<subseteq> S" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1547
  hence fMx: "finite ?Mx" using fS finite_subset by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1548
  from lx linS have linMx: "l \<in> ?Mx" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1549
  hence Mxne: "?Mx \<noteq> {}" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1550
  have xMS: "?xM \<subseteq> S" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1551
  hence fxM: "finite ?xM" using fS finite_subset by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1552
  from xu uinS have linxM: "u \<in> ?xM" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1553
  hence xMne: "?xM \<noteq> {}" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1554
  have ax:"?a \<le> x" using Mxne fMx by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1555
  have xb:"x \<le> ?b" using xMne fxM by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1556
  have "?a \<in> ?Mx" using Max_in[OF fMx Mxne] by simp hence ainS: "?a \<in> S" using MxS by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1557
  have "?b \<in> ?xM" using Min_in[OF fxM xMne] by simp hence binS: "?b \<in> S" using xMS by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1558
  have noy:"\<forall> y. ?a < y \<and> y < ?b \<longrightarrow> y \<notin> S"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1559
  proof(clarsimp)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1560
    fix y
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1561
    assume ay: "?a < y" and yb: "y < ?b" and yS: "y \<in> S"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1562
    from yS have "y\<in> ?Mx \<or> y\<in> ?xM" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1563
    moreover {assume "y \<in> ?Mx" hence "y \<le> ?a" using Mxne fMx by auto with ay have "False" by simp}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1564
    moreover {assume "y \<in> ?xM" hence "y \<ge> ?b" using xMne fxM by auto with yb have "False" by simp}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1565
    ultimately show "False" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1566
  qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1567
  from ainS binS noy ax xb px show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1568
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1569
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1570
lemma rinf_uset:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1571
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1572
  and nmi: "\<not> (Ifm (x#bs) (minusinf p))" (is "\<not> (Ifm (x#bs) (?M p))")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1573
  and npi: "\<not> (Ifm (x#bs) (plusinf p))" (is "\<not> (Ifm (x#bs) (?P p))")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1574
  and ex: "\<exists> x.  Ifm (x#bs) p" (is "\<exists> x. ?I x p")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1575
  shows "\<exists> (l,n) \<in> set (uset p). \<exists> (s,m) \<in> set (uset p). ?I ((Inum (x#bs) l / real n + Inum (x#bs) s / real m) / 2) p" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1576
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1577
  let ?N = "\<lambda> x t. Inum (x#bs) t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1578
  let ?U = "set (uset p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1579
  from ex obtain a where pa: "?I a p" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1580
  from bound0_I[OF rminusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] nmi
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1581
  have nmi': "\<not> (?I a (?M p))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1582
  from bound0_I[OF rplusinf_bound0[OF lp], where bs="bs" and b="x" and b'="a"] npi
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1583
  have npi': "\<not> (?I a (?P p))" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1584
  have "\<exists> (l,n) \<in> set (uset p). \<exists> (s,m) \<in> set (uset p). ?I ((?N a l/real n + ?N a s /real m) / 2) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1585
  proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1586
    let ?M = "(\<lambda> (t,c). ?N a t / real c) ` ?U"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1587
    have fM: "finite ?M" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1588
    from rminusinf_uset[OF lp nmi pa] rplusinf_uset[OF lp npi pa] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1589
    have "\<exists> (l,n) \<in> set (uset p). \<exists> (s,m) \<in> set (uset p). a \<le> ?N x l / real n \<and> a \<ge> ?N x s / real m" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1590
    then obtain "t" "n" "s" "m" where 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1591
      tnU: "(t,n) \<in> ?U" and smU: "(s,m) \<in> ?U" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1592
      and xs1: "a \<le> ?N x s / real m" and tx1: "a \<ge> ?N x t / real n" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1593
    from uset_l[OF lp] tnU smU numbound0_I[where bs="bs" and b="x" and b'="a"] xs1 tx1 have xs: "a \<le> ?N a s / real m" and tx: "a \<ge> ?N a t / real n" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1594
    from tnU have Mne: "?M \<noteq> {}" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1595
    hence Une: "?U \<noteq> {}" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1596
    let ?l = "Min ?M"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1597
    let ?u = "Max ?M"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1598
    have linM: "?l \<in> ?M" using fM Mne by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1599
    have uinM: "?u \<in> ?M" using fM Mne by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1600
    have tnM: "?N a t / real n \<in> ?M" using tnU by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1601
    have smM: "?N a s / real m \<in> ?M" using smU by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1602
    have lM: "\<forall> t\<in> ?M. ?l \<le> t" using Mne fM by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1603
    have Mu: "\<forall> t\<in> ?M. t \<le> ?u" using Mne fM by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1604
    have "?l \<le> ?N a t / real n" using tnM Mne by simp hence lx: "?l \<le> a" using tx by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1605
    have "?N a s / real m \<le> ?u" using smM Mne by simp hence xu: "a \<le> ?u" using xs by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1606
    from finite_set_intervals2[where P="\<lambda> x. ?I x p",OF pa lx xu linM uinM fM lM Mu]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1607
    have "(\<exists> s\<in> ?M. ?I s p) \<or> 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1608
      (\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p)" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1609
    moreover { fix u assume um: "u\<in> ?M" and pu: "?I u p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1610
      hence "\<exists> (tu,nu) \<in> ?U. u = ?N a tu / real nu" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1611
      then obtain "tu" "nu" where tuU: "(tu,nu) \<in> ?U" and tuu:"u= ?N a tu / real nu" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1612
      have "(u + u) / 2 = u" by auto with pu tuu 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1613
      have "?I (((?N a tu / real nu) + (?N a tu / real nu)) / 2) p" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1614
      with tuU have ?thesis by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1615
    moreover{
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1616
      assume "\<exists> t1\<in> ?M. \<exists> t2 \<in> ?M. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M) \<and> t1 < a \<and> a < t2 \<and> ?I a p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1617
      then obtain t1 and t2 where t1M: "t1 \<in> ?M" and t2M: "t2\<in> ?M" 
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
  1618
        and noM: "\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> ?M" and t1x: "t1 < a" and xt2: "a < t2" and px: "?I a p"
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
  1619
        by blast
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1620
      from t1M have "\<exists> (t1u,t1n) \<in> ?U. t1 = ?N a t1u / real t1n" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1621
      then obtain "t1u" "t1n" where t1uU: "(t1u,t1n) \<in> ?U" and t1u: "t1 = ?N a t1u / real t1n" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1622
      from t2M have "\<exists> (t2u,t2n) \<in> ?U. t2 = ?N a t2u / real t2n" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1623
      then obtain "t2u" "t2n" where t2uU: "(t2u,t2n) \<in> ?U" and t2u: "t2 = ?N a t2u / real t2n" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1624
      from t1x xt2 have t1t2: "t1 < t2" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1625
      let ?u = "(t1 + t2) / 2"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1626
      from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1627
      from lin_dense[OF lp noM t1x xt2 px t1lu ut2] have "?I ?u p" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1628
      with t1uU t2uU t1u t2u have ?thesis by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1629
    ultimately show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1630
  qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1631
  then obtain "l" "n" "s"  "m" where lnU: "(l,n) \<in> ?U" and smU:"(s,m) \<in> ?U" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1632
    and pu: "?I ((?N a l / real n + ?N a s / real m) / 2) p" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1633
  from lnU smU uset_l[OF lp] have nbl: "numbound0 l" and nbs: "numbound0 s" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1634
  from numbound0_I[OF nbl, where bs="bs" and b="a" and b'="x"] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1635
    numbound0_I[OF nbs, where bs="bs" and b="a" and b'="x"] pu
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1636
  have "?I ((?N x l / real n + ?N x s / real m) / 2) p" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1637
  with lnU smU
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1638
  show ?thesis by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1639
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1640
    (* The Ferrante - Rackoff Theorem *)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1641
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1642
theorem fr_eq: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1643
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1644
  shows "(\<exists> x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \<or> (Ifm (x#bs) (plusinf p)) \<or> (\<exists> (t,n) \<in> set (uset p). \<exists> (s,m) \<in> set (uset p). Ifm ((((Inum (x#bs) t)/  real n + (Inum (x#bs) s) / real m) /2)#bs) p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1645
  (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1646
proof
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1647
  assume px: "\<exists> x. ?I x p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1648
  have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1649
  moreover {assume "?M \<or> ?P" hence "?D" by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1650
  moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1651
    from rinf_uset[OF lp nmi npi] have "?F" using px by blast hence "?D" by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1652
  ultimately show "?D" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1653
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1654
  assume "?D" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1655
  moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1656
  moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1657
  moreover {assume f:"?F" hence "?E" by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1658
  ultimately show "?E" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1659
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1660
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1661
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1662
lemma fr_equsubst: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1663
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1664
  shows "(\<exists> x. Ifm (x#bs) p) = ((Ifm (x#bs) (minusinf p)) \<or> (Ifm (x#bs) (plusinf p)) \<or> (\<exists> (t,k) \<in> set (uset p). \<exists> (s,l) \<in> set (uset p). Ifm (x#bs) (usubst p (Add(Mul l t) (Mul k s) , 2*k*l))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1665
  (is "(\<exists> x. ?I x p) = (?M \<or> ?P \<or> ?F)" is "?E = ?D")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1666
proof
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1667
  assume px: "\<exists> x. ?I x p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1668
  have "?M \<or> ?P \<or> (\<not> ?M \<and> \<not> ?P)" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1669
  moreover {assume "?M \<or> ?P" hence "?D" by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1670
  moreover {assume nmi: "\<not> ?M" and npi: "\<not> ?P"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1671
    let ?f ="\<lambda> (t,n). Inum (x#bs) t / real n"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1672
    let ?N = "\<lambda> t. Inum (x#bs) t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1673
    {fix t n s m assume "(t,n)\<in> set (uset p)" and "(s,m) \<in> set (uset p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1674
      with uset_l[OF lp] have tnb: "numbound0 t" and np:"real n > 0" and snb: "numbound0 s" and mp:"real m > 0"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
  1675
        by auto
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1676
      let ?st = "Add (Mul m t) (Mul n s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1677
      from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" 
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
  1678
        by (simp add: mult_commute)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1679
      from tnb snb have st_nb: "numbound0 ?st" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1680
      have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32642
diff changeset
  1681
        using mnp mp np by (simp add: algebra_simps add_divide_distrib)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1682
      from usubst_I[OF lp mnp st_nb, where x="x" and bs="bs"] 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1683
      have "?I x (usubst p (?st,2*n*m)) = ?I ((?N t / real n + ?N s / real m) /2) p" by (simp only: st[symmetric])}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1684
    with rinf_uset[OF lp nmi npi px] have "?F" by blast hence "?D" by blast}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1685
  ultimately show "?D" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1686
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1687
  assume "?D" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1688
  moreover {assume m:"?M" from rminusinf_ex[OF lp m] have "?E" .}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1689
  moreover {assume p: "?P" from rplusinf_ex[OF lp p] have "?E" . }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1690
  moreover {fix t k s l assume "(t,k) \<in> set (uset p)" and "(s,l) \<in> set (uset p)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1691
    and px:"?I x (usubst p (Add (Mul l t) (Mul k s), 2*k*l))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1692
    with uset_l[OF lp] have tnb: "numbound0 t" and np:"real k > 0" and snb: "numbound0 s" and mp:"real l > 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1693
    let ?st = "Add (Mul l t) (Mul k s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1694
    from mult_pos_pos[OF np mp] have mnp: "real (2*k*l) > 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1695
      by (simp add: mult_commute)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1696
    from tnb snb have st_nb: "numbound0 ?st" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1697
    from usubst_I[OF lp mnp st_nb, where bs="bs"] px have "?E" by auto}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1698
  ultimately show "?E" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1699
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1700
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1701
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1702
    (* Implement the right hand side of Ferrante and Rackoff's Theorem. *)
35416
d8d7d1b785af replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents: 33639
diff changeset
  1703
definition ferrack :: "fm \<Rightarrow> fm" where
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1704
  "ferrack p = (let p' = rlfm (simpfm p); mp = minusinf p'; pp = plusinf p'
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1705
                in if (mp = T \<or> pp = T) then T else 
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1706
                   (let U = remdups(map simp_num_pair 
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1707
                     (map (\<lambda> ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m))
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1708
                           (alluopairs (uset p')))) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1709
                    in decr (disj mp (disj pp (evaldjf (simpfm o (usubst p')) U)))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1710
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1711
lemma uset_cong_aux:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1712
  assumes Ul: "\<forall> (t,n) \<in> set U. numbound0 t \<and> n >0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1713
  shows "((\<lambda> (t,n). Inum (x#bs) t /real n) ` (set (map (\<lambda> ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)) (alluopairs U)))) = ((\<lambda> ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (set U \<times> set U))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1714
  (is "?lhs = ?rhs")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1715
proof(auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1716
  fix t n s m
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1717
  assume "((t,n),(s,m)) \<in> set (alluopairs U)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1718
  hence th: "((t,n),(s,m)) \<in> (set U \<times> set U)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1719
    using alluopairs_set1[where xs="U"] by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1720
  let ?N = "\<lambda> t. Inum (x#bs) t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1721
  let ?st= "Add (Mul m t) (Mul n s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1722
  from Ul th have mnz: "m \<noteq> 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1723
  from Ul th have  nnz: "n \<noteq> 0" by auto  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1724
  have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1725
   using mnz nnz by (simp add: algebra_simps add_divide_distrib)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1726
 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1727
  thus "(real m *  Inum (x # bs) t + real n * Inum (x # bs) s) /
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1728
       (2 * real n * real m)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1729
       \<in> (\<lambda>((t, n), s, m).
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1730
             (Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2) `
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1731
         (set U \<times> set U)"using mnz nnz th  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1732
    apply (auto simp add: th add_divide_distrib algebra_simps split_def image_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1733
    by (rule_tac x="(s,m)" in bexI,simp_all) 
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46670
diff changeset
  1734
  (rule_tac x="(t,n)" in bexI,simp_all add: mult_commute)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1735
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1736
  fix t n s m
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1737
  assume tnU: "(t,n) \<in> set U" and smU:"(s,m) \<in> set U" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1738
  let ?N = "\<lambda> t. Inum (x#bs) t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1739
  let ?st= "Add (Mul m t) (Mul n s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1740
  from Ul smU have mnz: "m \<noteq> 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1741
  from Ul tnU have  nnz: "n \<noteq> 0" by auto  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1742
  have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1743
   using mnz nnz by (simp add: algebra_simps add_divide_distrib)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1744
 let ?P = "\<lambda> (t',n') (s',m'). (Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1745
 have Pc:"\<forall> a b. ?P a b = ?P b a"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1746
   by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1747
 from Ul alluopairs_set1 have Up:"\<forall> ((t,n),(s,m)) \<in> set (alluopairs U). n \<noteq> 0 \<and> m \<noteq> 0" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1748
 from alluopairs_ex[OF Pc, where xs="U"] tnU smU
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1749
 have th':"\<exists> ((t',n'),(s',m')) \<in> set (alluopairs U). ?P (t',n') (s',m')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1750
   by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1751
 then obtain t' n' s' m' where ts'_U: "((t',n'),(s',m')) \<in> set (alluopairs U)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1752
   and Pts': "?P (t',n') (s',m')" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1753
 from ts'_U Up have mnz': "m' \<noteq> 0" and nnz': "n'\<noteq> 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1754
 let ?st' = "Add (Mul m' t') (Mul n' s')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1755
   have st': "(?N t' / real n' + ?N s' / real m')/2 = ?N ?st' / real (2*n'*m')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1756
   using mnz' nnz' by (simp add: algebra_simps add_divide_distrib)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1757
 from Pts' have 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1758
   "(Inum (x # bs) t / real n + Inum (x # bs) s / real m)/2 = (Inum (x # bs) t' / real n' + Inum (x # bs) s' / real m')/2" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1759
 also have "\<dots> = ((\<lambda>(t, n). Inum (x # bs) t / real n) ((\<lambda>((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) ((t',n'),(s',m'))))" by (simp add: st')
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1760
 finally show "(Inum (x # bs) t / real n + Inum (x # bs) s / real m) / 2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1761
          \<in> (\<lambda>(t, n). Inum (x # bs) t / real n) `
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1762
            (\<lambda>((t, n), s, m). (Add (Mul m t) (Mul n s), 2 * n * m)) `
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1763
            set (alluopairs U)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1764
   using ts'_U by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1765
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1766
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1767
lemma uset_cong:
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1768
  assumes lp: "isrlfm p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1769
  and UU': "((\<lambda> (t,n). Inum (x#bs) t /real n) ` U') = ((\<lambda> ((t,n),(s,m)). (Inum (x#bs) t /real n + Inum (x#bs) s /real m)/2) ` (U \<times> U))" (is "?f ` U' = ?g ` (U\<times>U)")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1770
  and U: "\<forall> (t,n) \<in> U. numbound0 t \<and> n > 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1771
  and U': "\<forall> (t,n) \<in> U'. numbound0 t \<and> n > 0"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1772
  shows "(\<exists> (t,n) \<in> U. \<exists> (s,m) \<in> U. Ifm (x#bs) (usubst p (Add (Mul m t) (Mul n s),2*n*m))) = (\<exists> (t,n) \<in> U'. Ifm (x#bs) (usubst p (t,n)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1773
  (is "?lhs = ?rhs")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1774
proof
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1775
  assume ?lhs
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1776
  then obtain t n s m where tnU: "(t,n) \<in> U" and smU:"(s,m) \<in> U" and 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1777
    Pst: "Ifm (x#bs) (usubst p (Add (Mul m t) (Mul n s),2*n*m))" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1778
  let ?N = "\<lambda> t. Inum (x#bs) t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1779
  from tnU smU U have tnb: "numbound0 t" and np: "n > 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1780
    and snb: "numbound0 s" and mp:"m > 0"  by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1781
  let ?st= "Add (Mul m t) (Mul n s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1782
  from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1783
      by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1784
    from tnb snb have stnb: "numbound0 ?st" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1785
  have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1786
   using mp np by (simp add: algebra_simps add_divide_distrib)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1787
  from tnU smU UU' have "?g ((t,n),(s,m)) \<in> ?f ` U'" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1788
  hence "\<exists> (t',n') \<in> U'. ?g ((t,n),(s,m)) = ?f (t',n')"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1789
    by auto (rule_tac x="(a,b)" in bexI, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1790
  then obtain t' n' where tnU': "(t',n') \<in> U'" and th: "?g ((t,n),(s,m)) = ?f (t',n')" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1791
  from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1792
  from usubst_I[OF lp mnp stnb, where bs="bs" and x="x"] Pst 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1793
  have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1794
  from conjunct1[OF usubst_I[OF lp np' tnb', where bs="bs" and x="x"], symmetric] th[simplified split_def fst_conv snd_conv,symmetric] Pst2[simplified st[symmetric]]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1795
  have "Ifm (x # bs) (usubst p (t', n')) " by (simp only: st) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1796
  then show ?rhs using tnU' by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1797
next
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1798
  assume ?rhs
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1799
  then obtain t' n' where tnU': "(t',n') \<in> U'" and Pt': "Ifm (x # bs) (usubst p (t', n'))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1800
    by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1801
  from tnU' UU' have "?f (t',n') \<in> ?g ` (U\<times>U)" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1802
  hence "\<exists> ((t,n),(s,m)) \<in> (U\<times>U). ?f (t',n') = ?g ((t,n),(s,m))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1803
    by auto (rule_tac x="(a,b)" in bexI, auto)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1804
  then obtain t n s m where tnU: "(t,n) \<in> U" and smU:"(s,m) \<in> U" and 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1805
    th: "?f (t',n') = ?g((t,n),(s,m)) "by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1806
    let ?N = "\<lambda> t. Inum (x#bs) t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1807
  from tnU smU U have tnb: "numbound0 t" and np: "n > 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1808
    and snb: "numbound0 s" and mp:"m > 0"  by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1809
  let ?st= "Add (Mul m t) (Mul n s)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1810
  from mult_pos_pos[OF np mp] have mnp: "real (2*n*m) > 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1811
      by (simp add: mult_commute real_of_int_mult[symmetric] del: real_of_int_mult)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1812
    from tnb snb have stnb: "numbound0 ?st" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1813
  have st: "(?N t / real n + ?N s / real m)/2 = ?N ?st / real (2*n*m)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1814
   using mp np by (simp add: algebra_simps add_divide_distrib)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1815
  from U' tnU' have tnb': "numbound0 t'" and np': "real n' > 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1816
  from usubst_I[OF lp np' tnb', where bs="bs" and x="x",simplified th[simplified split_def fst_conv snd_conv] st] Pt'
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1817
  have Pst2: "Ifm (Inum (x # bs) (Add (Mul m t) (Mul n s)) / real (2 * n * m) # bs) p" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1818
  with usubst_I[OF lp mnp stnb, where x="x" and bs="bs"] tnU smU show ?lhs by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1819
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1820
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1821
lemma ferrack: 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1822
  assumes qf: "qfree p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1823
  shows "qfree (ferrack p) \<and> ((Ifm bs (ferrack p)) = (\<exists> x. Ifm (x#bs) p))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1824
  (is "_ \<and> (?rhs = ?lhs)")
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1825
proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1826
  let ?I = "\<lambda> x p. Ifm (x#bs) p"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1827
  fix x
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1828
  let ?N = "\<lambda> t. Inum (x#bs) t"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1829
  let ?q = "rlfm (simpfm p)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1830
  let ?U = "uset ?q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1831
  let ?Up = "alluopairs ?U"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1832
  let ?g = "\<lambda> ((t,n),(s,m)). (Add (Mul m t) (Mul n s) , 2*n*m)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1833
  let ?S = "map ?g ?Up"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1834
  let ?SS = "map simp_num_pair ?S"
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1835
  let ?Y = "remdups ?SS"
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1836
  let ?f= "(\<lambda> (t,n). ?N t / real n)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1837
  let ?h = "\<lambda> ((t,n),(s,m)). (?N t/real n + ?N s/ real m) /2"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1838
  let ?F = "\<lambda> p. \<exists> a \<in> set (uset p). \<exists> b \<in> set (uset p). ?I x (usubst p (?g(a,b)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1839
  let ?ep = "evaldjf (simpfm o (usubst ?q)) ?Y"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1840
  from rlfm_I[OF simpfm_qf[OF qf]] have lq: "isrlfm ?q" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1841
  from alluopairs_set1[where xs="?U"] have UpU: "set ?Up \<le> (set ?U \<times> set ?U)" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1842
  from uset_l[OF lq] have U_l: "\<forall> (t,n) \<in> set ?U. numbound0 t \<and> n > 0" .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1843
  from U_l UpU 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1844
  have "\<forall> ((t,n),(s,m)) \<in> set ?Up. numbound0 t \<and> n> 0 \<and> numbound0 s \<and> m > 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1845
  hence Snb: "\<forall> (t,n) \<in> set ?S. numbound0 t \<and> n > 0 "
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1846
    by (auto simp add: mult_pos_pos)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1847
  have Y_l: "\<forall> (t,n) \<in> set ?Y. numbound0 t \<and> n > 0" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1848
  proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1849
    { fix t n assume tnY: "(t,n) \<in> set ?Y" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1850
      hence "(t,n) \<in> set ?SS" by simp
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1851
      hence "\<exists> (t',n') \<in> set ?S. simp_num_pair (t',n') = (t,n)"
33639
603320b93668 New list theorems; added map_map to simpset, this is the prefered direction; allow sorting by a key
hoelzl
parents: 33063
diff changeset
  1852
        by (auto simp add: split_def simp del: map_map)
603320b93668 New list theorems; added map_map to simpset, this is the prefered direction; allow sorting by a key
hoelzl
parents: 33063
diff changeset
  1853
           (rule_tac x="((aa,ba),(ab,bb))" in bexI, simp_all)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1854
      then obtain t' n' where tn'S: "(t',n') \<in> set ?S" and tns: "simp_num_pair (t',n') = (t,n)" by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1855
      from tn'S Snb have tnb: "numbound0 t'" and np: "n' > 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1856
      from simp_num_pair_l[OF tnb np tns]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1857
      have "numbound0 t \<and> n > 0" . }
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1858
    thus ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1859
  qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1860
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1861
  have YU: "(?f ` set ?Y) = (?h ` (set ?U \<times> set ?U))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1862
  proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1863
     from simp_num_pair_ci[where bs="x#bs"] have 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1864
    "\<forall>x. (?f o simp_num_pair) x = ?f x" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1865
     hence th: "?f o simp_num_pair = ?f" using ext by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1866
    have "(?f ` set ?Y) = ((?f o simp_num_pair) ` set ?S)" by (simp add: image_compose)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1867
    also have "\<dots> = (?f ` set ?S)" by (simp add: th)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1868
    also have "\<dots> = ((?f o ?g) ` set ?Up)" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1869
      by (simp only: set_map o_def image_compose[symmetric])
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1870
    also have "\<dots> = (?h ` (set ?U \<times> set ?U))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1871
      using uset_cong_aux[OF U_l, where x="x" and bs="bs", simplified set_map image_compose[symmetric]] by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1872
    finally show ?thesis .
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1873
  qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1874
  have "\<forall> (t,n) \<in> set ?Y. bound0 (simpfm (usubst ?q (t,n)))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1875
  proof-
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1876
    { fix t n assume tnY: "(t,n) \<in> set ?Y"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1877
      with Y_l have tnb: "numbound0 t" and np: "real n > 0" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1878
      from usubst_I[OF lq np tnb]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1879
    have "bound0 (usubst ?q (t,n))"  by simp hence "bound0 (simpfm (usubst ?q (t,n)))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1880
      using simpfm_bound0 by simp}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1881
    thus ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1882
  qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1883
  hence ep_nb: "bound0 ?ep"  using evaldjf_bound0[where xs="?Y" and f="simpfm o (usubst ?q)"] by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1884
  let ?mp = "minusinf ?q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1885
  let ?pp = "plusinf ?q"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1886
  let ?M = "?I x ?mp"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1887
  let ?P = "?I x ?pp"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1888
  let ?res = "disj ?mp (disj ?pp ?ep)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1889
  from rminusinf_bound0[OF lq] rplusinf_bound0[OF lq] ep_nb
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1890
  have nbth: "bound0 ?res" by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1891
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1892
  from conjunct1[OF rlfm_I[OF simpfm_qf[OF qf]]] simpfm  
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1893
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1894
  have th: "?lhs = (\<exists> x. ?I x ?q)" by auto 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1895
  from th fr_equsubst[OF lq, where bs="bs" and x="x"] have lhfr: "?lhs = (?M \<or> ?P \<or> ?F ?q)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1896
    by (simp only: split_def fst_conv snd_conv)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1897
  also have "\<dots> = (?M \<or> ?P \<or> (\<exists> (t,n) \<in> set ?Y. ?I x (simpfm (usubst ?q (t,n)))))" 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1898
    using uset_cong[OF lq YU U_l Y_l]  by (simp only: split_def fst_conv snd_conv simpfm) 
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1899
  also have "\<dots> = (Ifm (x#bs) ?res)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1900
    using evaldjf_ex[where ps="?Y" and bs = "x#bs" and f="simpfm o (usubst ?q)",symmetric]
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1901
    by (simp add: split_def pair_collapse)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1902
  finally have lheq: "?lhs =  (Ifm bs (decr ?res))" using decr[OF nbth] by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1903
  hence lr: "?lhs = ?rhs" apply (unfold ferrack_def Let_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1904
    by (cases "?mp = T \<or> ?pp = T", auto) (simp add: disj_def)+
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1905
  from decr_qf[OF nbth] have "qfree (ferrack p)" by (auto simp add: Let_def ferrack_def)
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1906
  with lr show ?thesis by blast
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1907
qed
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1908
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1909
definition linrqe:: "fm \<Rightarrow> fm" where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1910
  "linrqe p = qelim (prep p) ferrack"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1911
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1912
theorem linrqe: "Ifm bs (linrqe p) = Ifm bs p \<and> qfree (linrqe p)"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1913
using ferrack qelim_ci prep
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1914
unfolding linrqe_def by auto
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1915
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1916
definition ferrack_test :: "unit \<Rightarrow> fm" where
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1917
  "ferrack_test u = linrqe (A (A (Imp (Lt (Sub (Bound 1) (Bound 0)))
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1918
    (E (Eq (Sub (Add (Bound 0) (Bound 2)) (Bound 1)))))))"
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1919
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1920
ML {* @{code ferrack_test} () *}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1921
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1922
oracle linr_oracle = {*
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1923
let
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1924
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1925
fun num_of_term vs (Free vT) = @{code Bound} (find_index (fn vT' => vT = vT') vs)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1926
  | num_of_term vs @{term "real (0::int)"} = @{code C} 0
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1927
  | num_of_term vs @{term "real (1::int)"} = @{code C} 1
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1928
  | num_of_term vs @{term "0::real"} = @{code C} 0
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1929
  | num_of_term vs @{term "1::real"} = @{code C} 1
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1930
  | num_of_term vs (Bound i) = @{code Bound} i
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1931
  | num_of_term vs (@{term "uminus :: real \<Rightarrow> real"} $ t') = @{code Neg} (num_of_term vs t')
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1932
  | num_of_term vs (@{term "op + :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) =
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1933
     @{code Add} (num_of_term vs t1, num_of_term vs t2)
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1934
  | num_of_term vs (@{term "op - :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) =
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1935
     @{code Sub} (num_of_term vs t1, num_of_term vs t2)
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1936
  | num_of_term vs (@{term "op * :: real \<Rightarrow> real \<Rightarrow> real"} $ t1 $ t2) = (case num_of_term vs t1
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1937
     of @{code C} i => @{code Mul} (i, num_of_term vs t2)
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1938
      | _ => error "num_of_term: unsupported multiplication")
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46670
diff changeset
  1939
  | num_of_term vs (@{term "real :: int \<Rightarrow> real"} $ t') =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46670
diff changeset
  1940
     (@{code C} (snd (HOLogic.dest_number t'))
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46670
diff changeset
  1941
       handle TERM _ => error ("num_of_term: unknown term"))
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46670
diff changeset
  1942
  | num_of_term vs t' =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46670
diff changeset
  1943
     (@{code C} (snd (HOLogic.dest_number t'))
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46670
diff changeset
  1944
       handle TERM _ => error ("num_of_term: unknown term"));
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1945
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1946
fun fm_of_term vs @{term True} = @{code T}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1947
  | fm_of_term vs @{term False} = @{code F}
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1948
  | fm_of_term vs (@{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) =
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1949
      @{code Lt} (@{code Sub} (num_of_term vs t1, num_of_term vs t2))
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1950
  | fm_of_term vs (@{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) =
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1951
      @{code Le} (@{code Sub} (num_of_term vs t1, num_of_term vs t2))
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1952
  | fm_of_term vs (@{term "op = :: real \<Rightarrow> real \<Rightarrow> bool"} $ t1 $ t2) =
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1953
      @{code Eq} (@{code Sub} (num_of_term vs t1, num_of_term vs t2)) 
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1954
  | fm_of_term vs (@{term "op \<longleftrightarrow> :: bool \<Rightarrow> bool \<Rightarrow> bool"} $ t1 $ t2) =
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1955
      @{code Iff} (fm_of_term vs t1, fm_of_term vs t2)
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
  1956
  | fm_of_term vs (@{term HOL.conj} $ t1 $ t2) = @{code And} (fm_of_term vs t1, fm_of_term vs t2)
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
  1957
  | fm_of_term vs (@{term HOL.disj} $ t1 $ t2) = @{code Or} (fm_of_term vs t1, fm_of_term vs t2)
38786
e46e7a9cb622 formerly unnamed infix impliciation now named HOL.implies
haftmann
parents: 38558
diff changeset
  1958
  | fm_of_term vs (@{term HOL.implies} $ t1 $ t2) = @{code Imp} (fm_of_term vs t1, fm_of_term vs t2)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1959
  | fm_of_term vs (@{term "Not"} $ t') = @{code NOT} (fm_of_term vs t')
38558
32ad17fe2b9c tuned quotes
haftmann
parents: 38549
diff changeset
  1960
  | fm_of_term vs (Const (@{const_name Ex}, _) $ Abs (xn, xT, p)) =
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1961
      @{code E} (fm_of_term (("", dummyT) :: vs) p)
38558
32ad17fe2b9c tuned quotes
haftmann
parents: 38549
diff changeset
  1962
  | fm_of_term vs (Const (@{const_name All}, _) $ Abs (xn, xT, p)) =
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1963
      @{code A} (fm_of_term (("", dummyT) ::  vs) p)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1964
  | fm_of_term vs t = error ("fm_of_term : unknown term " ^ Syntax.string_of_term @{context} t);
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1965
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1966
fun term_of_num vs (@{code C} i) = @{term "real :: int \<Rightarrow> real"} $ HOLogic.mk_number HOLogic.intT i
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1967
  | term_of_num vs (@{code Bound} n) = Free (nth vs n)
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1968
  | term_of_num vs (@{code Neg} t') = @{term "uminus :: real \<Rightarrow> real"} $ term_of_num vs t'
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1969
  | term_of_num vs (@{code Add} (t1, t2)) = @{term "op + :: real \<Rightarrow> real \<Rightarrow> real"} $
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1970
      term_of_num vs t1 $ term_of_num vs t2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1971
  | term_of_num vs (@{code Sub} (t1, t2)) = @{term "op - :: real \<Rightarrow> real \<Rightarrow> real"} $
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1972
      term_of_num vs t1 $ term_of_num vs t2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1973
  | term_of_num vs (@{code Mul} (i, t2)) = @{term "op * :: real \<Rightarrow> real \<Rightarrow> real"} $
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1974
      term_of_num vs (@{code C} i) $ term_of_num vs t2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1975
  | term_of_num vs (@{code CN} (n, i, t)) = term_of_num vs (@{code Add} (@{code Mul} (i, @{code Bound} n), t));
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1976
45740
132a3e1c0fe5 more antiquotations;
wenzelm
parents: 44779
diff changeset
  1977
fun term_of_fm vs @{code T} = @{term True} 
132a3e1c0fe5 more antiquotations;
wenzelm
parents: 44779
diff changeset
  1978
  | term_of_fm vs @{code F} = @{term False}
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1979
  | term_of_fm vs (@{code Lt} t) = @{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1980
      term_of_num vs t $ @{term "0::real"}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1981
  | term_of_fm vs (@{code Le} t) = @{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1982
      term_of_num vs t $ @{term "0::real"}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1983
  | term_of_fm vs (@{code Gt} t) = @{term "op < :: real \<Rightarrow> real \<Rightarrow> bool"} $
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1984
      @{term "0::real"} $ term_of_num vs t
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1985
  | term_of_fm vs (@{code Ge} t) = @{term "op \<le> :: real \<Rightarrow> real \<Rightarrow> bool"} $
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1986
      @{term "0::real"} $ term_of_num vs t
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1987
  | term_of_fm vs (@{code Eq} t) = @{term "op = :: real \<Rightarrow> real \<Rightarrow> bool"} $
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1988
      term_of_num vs t $ @{term "0::real"}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1989
  | term_of_fm vs (@{code NEq} t) = term_of_fm vs (@{code NOT} (@{code Eq} t))
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1990
  | term_of_fm vs (@{code NOT} t') = HOLogic.Not $ term_of_fm vs t'
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1991
  | term_of_fm vs (@{code And} (t1, t2)) = HOLogic.conj $ term_of_fm vs t1 $ term_of_fm vs t2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1992
  | term_of_fm vs (@{code Or} (t1, t2)) = HOLogic.disj $ term_of_fm vs t1 $ term_of_fm vs t2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1993
  | term_of_fm vs (@{code Imp}  (t1, t2)) = HOLogic.imp $ term_of_fm vs t1 $ term_of_fm vs t2
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1994
  | term_of_fm vs (@{code Iff} (t1, t2)) = @{term "op \<longleftrightarrow> :: bool \<Rightarrow> bool \<Rightarrow> bool"} $
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1995
      term_of_fm vs t1 $ term_of_fm vs t2;
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1996
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1997
in fn (ctxt, t) =>
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  1998
  let 
36853
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  1999
    val vs = Term.add_frees t [];
c8e4102b08aa modernized specifications; tuned reification
haftmann
parents: 35416
diff changeset
  2000
    val t' = (term_of_fm vs o @{code linrqe} o fm_of_term vs) t;
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 41849
diff changeset
  2001
  in (Thm.cterm_of (Proof_Context.theory_of ctxt) o HOLogic.mk_Trueprop o HOLogic.mk_eq) (t, t') end
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2002
end;
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2003
*}
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2004
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 47432
diff changeset
  2005
ML_file "ferrack_tac.ML"
47432
e1576d13e933 more standard method setup;
wenzelm
parents: 47142
diff changeset
  2006
e1576d13e933 more standard method setup;
wenzelm
parents: 47142
diff changeset
  2007
method_setup rferrack = {*
e1576d13e933 more standard method setup;
wenzelm
parents: 47142
diff changeset
  2008
  Args.mode "no_quantify" >>
e1576d13e933 more standard method setup;
wenzelm
parents: 47142
diff changeset
  2009
    (fn q => fn ctxt => SIMPLE_METHOD' (Ferrack_Tac.linr_tac ctxt (not q)))
e1576d13e933 more standard method setup;
wenzelm
parents: 47142
diff changeset
  2010
*} "decision procedure for linear real arithmetic"
e1576d13e933 more standard method setup;
wenzelm
parents: 47142
diff changeset
  2011
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2012
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2013
lemma
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2014
  fixes x :: real
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2015
  shows "2 * x \<le> 2 * x \<and> 2 * x \<le> 2 * x + 1"
49070
f00fee6d21d4 tuned proofs;
wenzelm
parents: 48891
diff changeset
  2016
  by rferrack
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2017
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2018
lemma
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2019
  fixes x :: real
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2020
  shows "\<exists>y \<le> x. x = y + 1"
49070
f00fee6d21d4 tuned proofs;
wenzelm
parents: 48891
diff changeset
  2021
  by rferrack
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2022
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2023
lemma
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2024
  fixes x :: real
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2025
  shows "\<not> (\<exists>z. x + z = x + z + 1)"
49070
f00fee6d21d4 tuned proofs;
wenzelm
parents: 48891
diff changeset
  2026
  by rferrack
29789
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2027
b4534c3e68f6 established session HOL-Reflection
haftmann
parents:
diff changeset
  2028
end