src/HOL/Integ/Barith.thy
author berghofe
Mon, 11 Oct 2004 16:47:50 +0200
changeset 15239 fb73c8154b19
parent 15232 388a6f431d83
child 15272 79a7a4f20f50
permissions -rwxr-xr-x
Tuned some proofs.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
     1
(*  Title:      HOL/Integ/Barith.thy
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
     2
    ID:         $Id$
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
     3
    Author:     Amine Chaieb, TU Muenchen
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
     4
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
     5
Simple decision procedure for bounded arithmetic
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
     6
*)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
     7
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
     8
theory Barith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
     9
imports Presburger
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    10
files ("barith.ML")
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    11
begin
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    12
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    13
lemma imp_commute: "(PROP P \<Longrightarrow> PROP Q \<Longrightarrow> PROP R) \<equiv>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    14
  (PROP Q \<Longrightarrow> PROP P \<Longrightarrow> PROP R)"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    15
proof
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    16
  assume h1: "PROP P \<Longrightarrow> PROP Q \<Longrightarrow> PROP R"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    17
  assume h2: "PROP Q"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    18
  assume h3: "PROP P"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    19
  from h3 h2 show "PROP R" by (rule h1)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    20
next
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    21
  assume h1: "PROP Q \<Longrightarrow> PROP P \<Longrightarrow> PROP R"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    22
  assume h2: "PROP P"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    23
  assume h3: "PROP Q"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    24
  from h3 h2 show "PROP R" by (rule h1)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    25
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    26
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    27
lemma imp_simplify: "(PROP P \<Longrightarrow> PROP P \<Longrightarrow> PROP Q) \<equiv> (PROP P \<Longrightarrow> PROP Q)"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    28
proof
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    29
  assume h1: "PROP P \<Longrightarrow> PROP P \<Longrightarrow> PROP Q"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    30
  assume h2: "PROP P"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    31
  from h2 h2 show "PROP Q" by (rule h1)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    32
next
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    33
  assume h: "PROP P \<Longrightarrow> PROP Q"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    34
  assume "PROP P"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    35
  then show "PROP Q" by (rule h)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    36
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    37
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    38
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    39
(* Abstraction of constants *)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    40
lemma abs_const: "(x::int) <= x \<and> x <= x"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    41
  by simp
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    42
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    43
(* Abstraction of Variables *)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    44
lemma abs_var: "l <= (x::int) \<and> x <= u \<Longrightarrow> l <= (x::int) \<and> x <= u"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    45
  by simp
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    46
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    47
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    48
(* Unary operators *)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    49
lemma abs_neg: "l <= (x::int) \<and> x <= u \<Longrightarrow>  -u <= -x \<and> -x <= -l"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    50
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    51
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    52
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    53
(* Binary operations *)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    54
(* Addition*)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    55
lemma abs_add: "\<lbrakk> l1 <= (x1::int) \<and> x1 <= u1 ; l2 <= (x2::int) \<and> x2 <= u2\<rbrakk> 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    56
  \<Longrightarrow>  l1 + l2 <= x1 + x2 \<and> x1 + x2 <= u1 + u2"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    57
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    58
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    59
lemma abs_sub: "\<lbrakk> l1 <= (x1::int) \<and> x1 <= u1 ; l2 <= (x2::int) \<and> x2 <= u2\<rbrakk> 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    60
  \<Longrightarrow>  l1 - u2 <= x1 - x2 \<and> x1 - x2 <= u1 - l2"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    61
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    62
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    63
lemma abs_sub_x: "l <= (x::int) \<and> x <= u \<Longrightarrow> 0 <= x - x \<and> x - x <= 0"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    64
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    65
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    66
(* For resolving the last step*)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    67
lemma subinterval: "\<lbrakk>l <= (e::int) \<and> e <= u ; l' <= l ; u <= u' \<rbrakk>
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    68
  \<Longrightarrow> l' <= e \<and> e <= u'"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    69
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    70
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    71
lemma min_max_minus : "min (-a ::int) (-b) = - max a b"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    72
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    73
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    74
lemma max_min_minus : " max (-a ::int) (-b) = - min a b"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    75
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    76
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    77
lemma max_max_commute : "max (max (a::int) b) (max c d) = max (max a c) (max b d)"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    78
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    79
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    80
lemma min_min_commute : "min (min (a::int) b) (min c d) = min (min a c) (min b d)"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
    81
  by arith
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    82
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    83
lemma zintervals_min: "\<lbrakk> l1 <= (x1::int) \<and> x1<= u1 ; l2 <= x2 \<and> x2 <= u2 \<rbrakk> 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    84
  \<Longrightarrow> min l1 l2 <= x1 \<and> x1 <= max u1 u2" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    85
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    86
lemma zmult_zle_mono: "(i::int) \<le> j \<Longrightarrow> 0 \<le> k \<Longrightarrow> k * i \<le> k * j"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    87
  apply (erule order_le_less [THEN iffD1, THEN disjE, of "0::int"])
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    88
  apply (erule order_le_less [THEN iffD1, THEN disjE])
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    89
  apply (rule order_less_imp_le)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    90
  apply (rule zmult_zless_mono2)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    91
  apply simp_all
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    92
  done
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    93
  
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    94
lemma zmult_mono:
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    95
  assumes l1_pos : "0 <= l1"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    96
  and l2_pos : "0 <= l2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    97
  and l1_le : "l1 <= (x1::int)"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    98
  and l2_le : "l2 <= (x2::int)"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
    99
  shows "l1*l2 <= x1*x2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   100
proof -
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   101
  from l1_pos and l1_le have x1_pos: "0 \<le> x1" by (rule order_trans)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   102
  from l1_le and l2_pos
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   103
  have "l2 * l1 \<le> l2 * x1" by (rule zmult_zle_mono)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   104
  then have "l1 * l2 \<le> x1 * l2" by (simp add: mult_ac)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   105
  also from l2_le and x1_pos
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   106
  have "x1 * l2 \<le> x1 * x2" by (rule zmult_zle_mono)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   107
  finally show ?thesis .
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   108
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   109
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   110
lemma zinterval_lposlpos:
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   111
  assumes x1_lu : "l1 <= (x1::int) \<and> x1 <= u1"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   112
  and     x2_lu : "l2 <= (x2::int) \<and> x2 <= u2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   113
  and     l1_pos : "0 <= l1"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   114
  and     l2_pos : "0 <= l2"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   115
  shows "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= x1 * x2 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   116
  \<and> x1 * x2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   117
proof -
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   118
  from x1_lu have l1_le : "l1 <= x1" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   119
  from x1_lu have x1_le : "x1 <= u1" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   120
  from x2_lu have l2_le : "l2 <= x2" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   121
  from x2_lu have x2_le : "x2 <= u2" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   122
  from x1_lu have l1_leu : "l1 <= u1" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   123
  from x2_lu have l2_leu : "l2 <= u2" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   124
  from l1_pos l2_pos l1_le l2_le 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   125
  have l1l2_le : "l1*l2 <= x1*x2" by (simp add: zmult_mono)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   126
  from l1_pos x1_lu have x1_pos : "0 <= x1" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   127
  from l2_pos x2_lu have x2_pos : "0 <= x2" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   128
  from l1_pos x1_lu have u1_pos : "0 <= u1" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   129
  from l2_pos x2_lu have u2_pos : "0 <= u2" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   130
  from x1_pos x2_pos x1_le x2_le 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   131
  have x1x2_le : "x1*x2 <= u1*u2" by (simp add: zmult_mono)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   132
  from l2_leu l1_pos have l1l2_leu2 : "l1*l2 <= l1*u2" 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   133
    by (simp add: zmult_zle_mono)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   134
  from l1l2_leu2 have min1 : "l1*l2 = min (l1*l2) (l1*u2)" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   135
  from l2_leu u1_pos have u1l2_le : "u1*l2 <=u1*u2" by (simp add: zmult_zle_mono)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   136
  from u1l2_le have min2 : "u1*l2 = min (u1*l2) (u1*u2)" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   137
  from l1_leu l2_pos have "l2*l1 <= l2*u1" by (simp add:zmult_zle_mono) 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   138
  then have l1l2_le_u1l2 : "l1*l2 <= u1*l2" by (simp add: mult_ac)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   139
  from min1 min2 l1l2_le_u1l2 have  min_th : 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   140
    "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) = (l1*l2)" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   141
  from l1l2_leu2 have max1 : "l1*u2 = max (l1*l2) (l1*u2)" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   142
  from u1l2_le have max2 : "u1*u2 = max (u1*l2) (u1*u2)" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   143
  from l1_leu u2_pos have "u2*l1 <= u2*u1" by (simp add:zmult_zle_mono) 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   144
  then have l1u2_le_u1u2 : "l1*u2 <= u1*u2" by (simp add: mult_ac)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   145
  from max1 max2 l1u2_le_u1u2 have  max_th : 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   146
    "max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2)) = (u1*u2)" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   147
  from min_th have min_th' :  "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= l1*l2" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   148
  from max_th have max_th' : "u1*u2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   149
  from min_th' max_th' l1l2_le x1x2_le 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   150
  show ?thesis by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   151
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   152
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   153
lemma min_le_I1 : "min (a::int) b <= a" by arith
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   154
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   155
lemma min_le_I2 : "min (a::int) b <= b" by arith
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   156
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   157
lemma zinterval_lneglpos :
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   158
  assumes  x1_lu : "l1 <= (x1::int) \<and> x1 <= u1"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   159
  and     x2_lu : "l2 <= (x2::int) \<and> x2 <= u2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   160
  and     l1_neg : "l1 <= 0"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   161
  and x1_pos : "0 <= x1" 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   162
  and     l2_pos : "0 <= l2"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   163
  shows "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= x1 * x2 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   164
  \<and> x1 * x2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   165
proof -
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   166
  from x1_lu x1_pos have x1_0_u1: "0 <= x1 \<and> x1 <= u1" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   167
  from l1_neg have ml1_pos: "0 <= -l1" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   168
  from x1_lu x1_pos have u1_pos: "0 <= u1" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   169
  from x2_lu l2_pos have u2_pos: "0 <= u2" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   170
  from x2_lu have l2_le_u2: "l2 <= u2" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   171
  from l2_le_u2 u1_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   172
  have u1l2_le_u1u2: "u1*l2 <= u1*u2" by (rule zmult_zle_mono)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   173
  have trv_0: "(0::int) <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   174
  from trv_0 trv_0 u1_pos l2_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   175
  have "0*0 <= u1*l2" by (rule zmult_mono)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   176
  then have u1l2_pos: "0 <= u1*l2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   177
  from l1_neg have ml1_pos: "0 <= -l1" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   178
  from trv_0 trv_0 ml1_pos l2_pos have "0*0 <= (-l1)*l2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   179
    by (rule zmult_mono)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   180
  then have "0 <= -(l1*l2)" by simp  
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   181
  then have "0 - (-(l1*l2)) <= 0" by arith 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   182
  then have l1l2_neg: "l1*l2 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   183
  from trv_0 trv_0 ml1_pos u2_pos have "0*0 <= (-l1)*u2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   184
    by (rule zmult_mono)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   185
  then have "0 <= -(l1*u2)" by simp  
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   186
  then have "0 - (-(l1*u2)) <= 0" by arith 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   187
  then have l1u2_neg: "l1*u2 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   188
  from l1l2_neg u1l2_pos have l1l2_le_u1l2: "l1*l2 <= u1*l2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   189
  from l1u2_neg u1l2_pos have l1u2_le_u1l2: "l1*u2 <= u1*l2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   190
  from ml1_pos l2_le_u2 have "(-l1)*l2 <= (-l1)*u2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   191
    by (simp only: zmult_zle_mono) 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   192
  then have l1u2_le_l1l2: "l1*u2 <= l1*l2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   193
  from l1u2_le_l1l2 l1l2_le_u1l2 u1l2_le_u1u2 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   194
  have min1: "l1*u2 = min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2))" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   195
    by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   196
  from u1l2_pos u1l2_le_u1u2 have "0 = min (min (0 * l2) (0 * u2)) (min (u1 * l2) (u1 * u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   197
    by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   198
  with l1u2_neg min1 have minth: "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <=
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   199
    min (min (0 * l2) (0 * u2)) (min (u1 * l2) (u1 * u2))" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   200
  from l1u2_le_l1l2 l1l2_le_u1l2 u1l2_le_u1u2 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   201
  have max1: "u1*u2 = max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   202
    by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   203
  from u1l2_pos u1l2_le_u1u2
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   204
  have "u1*u2 = max (max (0 * l2) (0 * u2)) (max (u1 * l2) (u1 * u2))" by arith 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   205
  with max1 have "max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   206
    max (max (0 * l2) (0 * u2)) (max (u1 * l2) (u1 * u2))" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   207
  then have maxth: " max (max (0 * l2) (0 * u2)) (max (u1 * l2) (u1 * u2)) <=
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   208
    max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   209
  from x1_0_u1 x2_lu trv_0 l2_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   210
  have x1x2_0_u: "min (min (0 * l2) (0 * u2)) (min (u1 * l2) (u1 * u2)) <= x1 * x2 &
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   211
    x1 * x2 <= max (max (0 * l2) (0 * u2)) (max (u1 * l2) (u1 * u2))" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   212
    by (rule zinterval_lposlpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   213
  thus ?thesis using minth maxth by (rule subinterval)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   214
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   215
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   216
lemma zinterval_lneglneg :
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   217
  assumes  x1_lu : "l1 <= (x1::int) \<and> x1 <= u1"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   218
  and     x2_lu : "l2 <= (x2::int) \<and> x2 <= u2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   219
  and     l1_neg : "l1 <= 0"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   220
  and     x1_pos : "0 <= x1" 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   221
  and     l2_neg : "l2 <= 0"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   222
  and     x2_pos : "0 <= x2"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   223
  shows "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= x1 * x2 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   224
  \<and> x1 * x2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   225
proof -
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   226
  from x1_lu x1_pos have x1_0_u1: "0 <= x1 \<and> x1 <= u1" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   227
  from l1_neg have ml1_pos: "0 <= -l1" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   228
  from l1_neg have l1_le0: "l1 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   229
  from x1_lu x1_pos have u1_pos: "0 <= u1" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   230
  from x2_lu x2_pos have x2_0_u2: "0 <= x2 \<and> x2 <= u2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   231
  from l2_neg have ml2_pos: "0 <= -l2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   232
  from l2_neg have l2_le0: "l2 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   233
  from x2_lu x2_pos have u2_pos: "0 <= u2" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   234
  have trv_0: "(0::int) <= 0" by simp
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   235
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   236
  from x1_lu x2_0_u2 l1_le0 x1_pos trv_0
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   237
  have x1x2_th1: 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   238
    "min (min (l1 * 0) (l1 * u2)) (min (u1 * 0) (u1 * u2)) \<le> x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   239
    x1 * x2 \<le> max (max (l1 * 0) (l1 * u2)) (max (u1 * 0) (u1 * u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   240
    by (rule zinterval_lneglpos)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   241
    
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   242
  have x1x2_eq_x2x1: "x1*x2 = x2*x1" by (simp add: mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   243
  from x2_lu x1_0_u1 l2_le0 x2_pos trv_0
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   244
  have
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   245
    "min (min (l2 * 0) (l2 * u1)) (min (u2 * 0) (u2 * u1)) \<le> x2 * x1 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   246
    x2 * x1 \<le> max (max (l2 * 0) (l2 * u1)) (max (u2 * 0) (u2 * u1))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   247
    by (rule zinterval_lneglpos)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   248
    
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   249
  then have x1x2_th2: 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   250
    "min (min (l2 * 0) (l2 * u1)) (min (u2 * 0) (u2 * u1)) \<le> x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   251
    x1 * x2 \<le> max (max (l2 * 0) (l2 * u1)) (max (u2 * 0) (u2 * u1))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   252
    by (simp add: x1x2_eq_x2x1)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   253
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   254
  from x1x2_th1 x1x2_th2 have x1x2_th3:
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   255
    "min (min (min (l1 * 0) (l1 * u2)) (min (u1 * 0) (u1 * u2)))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   256
    (min (min (l2 * 0) (l2 * u1)) (min (u2 * 0) (u2 * u1)))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   257
    \<le> x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   258
    x1 * x2
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   259
    \<le> max (max (max (l1 * 0) (l1 * u2)) (max (u1 * 0) (u1 * u2)))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   260
    (max (max (l2 * 0) (l2 * u1)) (max (u2 * 0) (u2 * u1)))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   261
    by (rule zintervals_min)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   262
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   263
  from trv_0 trv_0 ml1_pos u2_pos 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   264
  have "0*0 <= -l1*u2" by (rule zmult_mono) 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   265
  then have l1u2_neg: "l1*u2 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   266
  from l1u2_neg have min_l1u2_0: "min (0) (l1*u2) = l1*u2" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   267
  from l1u2_neg have max_l1u2_0: "max (0) (l1*u2) = 0" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   268
  from trv_0 trv_0 u1_pos u2_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   269
  have "0*0 <= u1*u2" by (rule zmult_mono) 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   270
  then have u1u2_pos: "0 <= u1*u2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   271
  from u1u2_pos have min_0_u1u2: "min 0 (u1*u2) = 0" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   272
  from u1u2_pos have max_0_u1u2: "max 0 (u1*u2) = u1*u2" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   273
  from trv_0 trv_0 ml2_pos u1_pos have "0*0 <= -l2*u1" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   274
    by (rule zmult_mono) 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   275
  then have l2u1_neg: "l2*u1 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   276
  from l2u1_neg have min_l2u1_0: "min 0 (l2*u1) = l2*u1" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   277
  from l2u1_neg have max_l2u1_0: "max 0 (l2*u1) = 0" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   278
  from min_l1u2_0 min_0_u1u2 min_l2u1_0 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   279
  have min_th1:
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   280
    "min (l2*u1) (l1*u2) <= min (min (min (l1 * 0) (l1 * u2)) (min (u1 * 0) (u1 * u2)))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   281
    (min (min (l2 * 0) (l2 * u1)) (min (u2 * 0) (u2 * u1)))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   282
    by (simp add: min_commute mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   283
  from max_l1u2_0 max_0_u1u2 max_l2u1_0 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   284
  have max_th1: "max (max (max (l1 * 0) (l1 * u2)) (max (u1 * 0) (u1 * u2)))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   285
    (max (max (l2 * 0) (l2 * u1)) (max (u2 * 0) (u2 * u1))) <= u1*u2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   286
    by (simp add: max_commute mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   287
  from x1x2_th3 min_th1 max_th1
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   288
  have x1x2_th4: "min (l2*u1) (l1*u2) <= x1*x2 \<and> x1*x2 <= u1*u2" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   289
    by (rule subinterval)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   290
    
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   291
  have "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   292
    min (min (l1*l2) (u1*u2)) (min (l1*u2) (l2*u1))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   293
    by (simp add: min_min_commute min_commute mult_ac) 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   294
  moreover have "min (min (l1*l2) (u1*u2)) (min (l1*u2) (l2*u1)) <= min (l1*u2) (l2*u1)" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   295
    by (rule min_le_I2)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   296
  ultimately have "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= min (l1*u2) (l2*u1)"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   297
    by simp 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   298
  then  have min_le1: "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <=min (l2*u1) (l1*u2)" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   299
    by (simp add: min_commute mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   300
  have "u1*u2 <= max (u1*l2) (u1*u2)" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   301
    by (rule le_maxI2) 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   302
    
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   303
  moreover have "max (u1*l2) (u1*u2) <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   304
    by (rule le_maxI2)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   305
  then have max_le1: "u1*u2 <= max (max (l1 * l2) (l1 * u2)) (max (u1 * l2) (u1 * u2))" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   306
    by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   307
  with x1x2_th4 min_le1 show ?thesis by (rule subinterval)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   308
qed
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   309
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   310
lemma zinterval_lpos:
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   311
  assumes x1_lu : "l1 <= (x1::int) \<and> x1 <= u1"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   312
  and     x2_lu : "l2 <= (x2::int) \<and> x2 <= u2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   313
  and     l1_pos: "0 <= l1"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   314
  shows "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= x1 * x2 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   315
  \<and> x1 * x2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   316
proof -
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   317
  from x1_lu have l1_le : "l1 <= x1" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   318
  from x1_lu have x1_le : "x1 <= u1" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   319
  from x2_lu have l2_le : "l2 <= x2" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   320
  from x2_lu have x2_le : "x2 <= u2" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   321
  from x1_lu have l1_leu : "l1 <= u1" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   322
  from x2_lu have l2_leu : "l2 <= u2" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   323
  have "(0 <= l2) \<or> (l2 < 0 \<and> 0<= x2) \<or> (x2 <0 \<and> 0 <= u2) \<or> (u2 <0)" by arith
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   324
  thus ?thesis
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   325
  proof (elim disjE conjE)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   326
    assume l2_pos: "0 <= l2"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   327
    with x1_lu x2_lu l1_pos show ?thesis by (rule zinterval_lposlpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   328
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   329
    assume l2_neg: "l2 < 0" and x2_pos: "0<= x2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   330
    from l2_neg have l2_le_0 : "l2 <= 0" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   331
    from x2_lu x1_lu l2_le_0 x2_pos l1_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   332
    have th1: 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   333
      "min (min (l2 * l1) (l2 * u1)) (min (u2 * l1) (u2 * u1)) \<le> x2 * x1 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   334
      x2 * x1 \<le> max (max (l2 * l1) (l2 * u1)) (max (u2 * l1) (u2 * u1))" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   335
      by (rule zinterval_lneglpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   336
    have mth1: "min (min (l2 * l1) (l2 * u1)) (min (u2 * l1) (u2 * u1)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   337
      min (min (l1 * l2) (l1 * u2)) (min (u1 * l2) (u1 * u2))" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   338
      by (simp add: min_min_commute mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   339
    have mth2: "max (max (l2 * l1) (l2 * u1)) (max (u2 * l1) (u2 * u1)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   340
      max (max (l1 * l2) (l1 * u2)) (max (u1 * l2) (u1 * u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   341
      by (simp add: max_max_commute mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   342
    have x1x2_th: "x2*x1 = x1*x2" by (simp add: mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   343
    from th1 mth1 mth2 x1x2_th have 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   344
      "min (min (l1 * l2) (l1 * u2)) (min (u1 * l2) (u1 * u2)) \<le> x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   345
      x1 * x2 \<le> max (max (l1 * l2) (l1 * u2)) (max (u1 * l2) (u1 * u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   346
      by auto
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   347
    thus ?thesis by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   348
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   349
    assume x2_neg: "x2 <0" and u2_pos: "0 <= u2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   350
    from x2_lu x2_neg have mx2_mu2_ml2: "-u2 <= -x2 \<and> -x2 <= -l2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   351
    from u2_pos have mu2_neg: "-u2 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   352
    from x2_neg have mx2_pos: "0 <= -x2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   353
    from mx2_mu2_ml2 x1_lu mu2_neg mx2_pos l1_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   354
    have mx1x2_lu: 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   355
      "min (min (- u2 * l1) (- u2 * u1)) (min (- l2 * l1) (- l2 * u1))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   356
      \<le> - x2 * x1 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   357
      - x2 * x1 \<le> max (max (- u2 * l1) (- u2 * u1)) (max (- l2 * l1) (- l2 * u1))"      
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   358
      by (rule zinterval_lneglpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   359
    have min_eq_mmax: 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   360
      "min (min (- u2 * l1) (- u2 * u1)) (min (- l2 * l1) (- l2 * u1)) = 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   361
      - max (max (u2 * l1) (u2 * u1)) (max (l2 * l1) (l2 * u1))" 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   362
      by (simp add: min_max_minus max_min_minus)
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   363
    have max_eq_mmin: 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   364
      " max (max (- u2 * l1) (- u2 * u1)) (max (- l2 * l1) (- l2 * u1)) = 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   365
      -min (min (u2 * l1) (u2 * u1)) (min (l2 * l1) (l2 * u1))"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   366
      by (simp add: min_max_minus max_min_minus)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   367
    from mx1x2_lu min_eq_mmax max_eq_mmin 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   368
    have "- max (max (u2 * l1) (u2 * u1)) (max (l2 * l1) (l2 * u1))<= - x1 * x2 &
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   369
      - x1*x2 <=  -min (min (u2 * l1) (u2 * u1)) (min (l2 * l1) (l2 * u1))" by (simp add: mult_ac)
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   370
    thus ?thesis by (simp add: min_min_commute min_commute max_commute max_max_commute mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   371
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   372
    assume u2_neg: "u2 < 0"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   373
    from x2_lu have mx2_lu: "-u2 <= -x2 \<and> -x2 <= -l2" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   374
    from u2_neg have mu2_pos: "0 <= -u2" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   375
    from x1_lu mx2_lu l1_pos mu2_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   376
    have "min (min (l1 * - u2) (l1 * - l2)) (min (u1 * - u2) (u1 * - l2))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   377
      \<le> x1 * - x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   378
      x1 * - x2 \<le> max (max (l1 * - u2) (l1 * - l2)) (max (u1 * - u2) (u1 * - l2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   379
      by (rule zinterval_lposlpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   380
    then have mx1x2_lu:
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   381
      "min (min (-l1 * u2) (- l1 * l2)) (min (- u1 * u2) (- u1 * l2)) \<le> - x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   382
      - x1 * x2 \<le> max (max (- l1 * u2) (- l1 * l2)) (max (- u1 * u2) (- u1 * l2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   383
      by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   384
    moreover have "min (min (-l1 * u2) (- l1 * l2)) (min (- u1 * u2) (- u1 * l2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   385
      - max (max (l1 * u2) ( l1 * l2)) (max ( u1 * u2) ( u1 * l2)) " 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   386
      by (simp add: min_max_minus max_min_minus)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   387
    moreover have
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   388
      "max (max (- l1 * u2) (- l1 * l2)) (max (- u1 * u2) (- u1 * l2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   389
      - min (min (l1 * u2) (l1 * l2)) (min (u1 * u2) (u1 * l2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   390
      by (simp add: min_max_minus max_min_minus)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   391
    ultimately have "- max (max (l1 * u2) ( l1 * l2)) (max ( u1 * u2) ( u1 * l2))\<le> - x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   392
      - x1 * x2 \<le> - min (min (l1 * u2) (l1 * l2)) (min (u1 * u2) (u1 * l2)) " by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   393
    thus ?thesis by (simp add: max_commute min_commute)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   394
  qed
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   395
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   396
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   397
lemma zinterval_uneg :
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   398
assumes x1_lu : "l1 <= (x1::int) \<and> x1 <= u1"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   399
  and     x2_lu : "l2 <= (x2::int) \<and> x2 <= u2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   400
  and     u1_neg: "u1 <= 0"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   401
  shows "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= x1 * x2 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   402
  \<and> x1 * x2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   403
proof -
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   404
  from x1_lu  have mx1_lu : "-u1 <= -x1 \<and> -x1 <= -l1" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   405
  from u1_neg have mu1_pos : "0 <= -u1" by arith
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   406
  with mx1_lu x2_lu have mx1x2_lu : 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   407
    "min (min (- u1 * l2) (- u1 * u2)) (min (- l1 * l2) (- l1 * u2))
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   408
    \<le> - x1 * x2 \<and> - x1 * x2 \<le> 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   409
    max (max (- u1 * l2) (- u1 * u2)) (max (- l1 * l2) (- l1 * u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   410
    by (rule zinterval_lpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   411
  moreover have 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   412
    "min (min (- u1 * l2) (- u1 * u2)) (min (- l1 * l2) (- l1 * u2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   413
    - max (max (u1 * l2) (u1 * u2)) (max (l1 * l2) (l1 * u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   414
    by (simp add: min_max_minus max_min_minus)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   415
  moreover have 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   416
    "max (max (- u1 * l2) (- u1 * u2)) (max (- l1 * l2) (- l1 * u2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   417
    - min (min (u1 * l2) ( u1 * u2)) (min (l1 * l2) (l1 * u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   418
    by (simp add: min_max_minus max_min_minus)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   419
  ultimately have "- max (max (u1 * l2) (u1 * u2)) (max (l1 * l2) (l1 * u2)) \<le> - x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   420
    - x1 * x2 \<le>  - min (min (u1 * l2) ( u1 * u2)) (min (l1 * l2) (l1 * u2))" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   421
  then show ?thesis by (simp add: min_commute max_commute mult_ac)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   422
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   423
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   424
lemma zinterval_lnegxpos:
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   425
  assumes x1_lu : "l1 <= (x1::int) \<and> x1 <= u1"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   426
  and     x2_lu : "l2 <= (x2::int) \<and> x2 <= u2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   427
  and     l1_neg: "l1 <= 0"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   428
  and     x1_pos: "0<= x1"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   429
  shows "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= x1 * x2 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   430
  \<and> x1 * x2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   431
proof -
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   432
  have "(0 <= l2) \<or> (l2 < 0 \<and> 0<= x2) \<or> (x2 <0 \<and> 0 <= u2) \<or> (u2 <= 0)" by arith
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   433
  thus ?thesis
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   434
  proof (elim disjE conjE)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   435
    assume l2_pos: "0 <= l2"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   436
    with x2_lu x1_lu have 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   437
      "min (min (l2 * l1) (l2 * u1)) (min (u2 * l1) (u2 * u1)) \<le> x2 * x1 \<and>
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   438
      x2 * x1 \<le> max (max (l2 * l1) (l2 * u1)) (max (u2 * l1) (u2 * u1))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   439
      by (rule zinterval_lpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   440
    moreover have "min (min (l2 * l1) (l2 * u1)) (min (u2 * l1) (u2 * u1)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   441
      min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   442
      by (simp add: mult_ac min_commute min_min_commute)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   443
    moreover have "max (max (l2 * l1) (l2 * u1)) (max (u2 * l1) (u2 * u1)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   444
      max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   445
      by (simp add: mult_ac max_commute max_max_commute)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   446
    ultimately show ?thesis by (simp add: mult_ac)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   447
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   448
    assume l2_neg: "l2 < 0" and x2_pos: " 0<= x2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   449
    from l1_neg have l1_le0: "l1 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   450
    from l2_neg have l2_le0: "l2 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   451
    from x1_lu x2_lu l1_le0 x1_pos l2_le0 x2_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   452
    show ?thesis by (rule zinterval_lneglneg)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   453
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   454
    assume x2_neg: "x2 <0" and u2_pos: "0 <= u2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   455
    from x2_lu have mx2_lu: "-u2 <= -x2 \<and> -x2 <= -l2" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   456
    from x2_neg have mx2_pos: "0 <= -x2" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   457
    from u2_pos have mu2_neg: "-u2 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   458
    from l1_neg have l1_le0: "l1 <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   459
    from x1_lu mx2_lu l1_le0 x1_pos mu2_neg mx2_pos
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   460
    have "min (min (l1 * - u2) (l1 * - l2)) (min (u1 * - u2) (u1 * - l2))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   461
      \<le> x1 * - x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   462
      x1 * - x2 \<le> max (max (l1 * - u2) (l1 * - l2)) (max (u1 * - u2) (u1 * - l2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   463
      by (rule zinterval_lneglneg)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   464
    then have "min (min (- l1 * u2) (- l1 * l2)) (min (- u1 * u2) (- u1 * l2))
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   465
      \<le> - x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   466
      - x1 * x2 \<le> max (max (- l1 * u2) (- l1 * l2)) (max (- u1 * u2) (- u1 * l2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   467
      by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   468
    moreover have "min (min (- l1 * u2) (- l1 * l2)) (min (- u1 * u2) (- u1 * l2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   469
      - max (max (l1 * u2) (l1 * l2)) (max (u1 * u2) (u1 * l2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   470
      by (simp add: min_max_minus max_min_minus)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   471
    moreover have "max (max (- l1 * u2) (- l1 * l2)) (max (- u1 * u2) (- u1 * l2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   472
      - min (min (l1 * u2) (l1 * l2)) (min (u1 * u2) (u1 * l2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   473
      by (simp add: min_max_minus max_min_minus)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   474
    ultimately have "- max (max (l1 * u2) (l1 * l2)) (max (u1 * u2) (u1 * l2)) \<le> - x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   475
      - x1 * x2 \<le>  - min (min (l1 * u2) (l1 * l2)) (min (u1 * u2) (u1 * l2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   476
      by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   477
    thus ?thesis by (simp add: min_commute max_commute mult_ac) 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   478
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   479
    assume u2_neg: "u2 <= 0"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   480
    with x2_lu x1_lu
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   481
    have "min (min (l2 * l1) (l2 * u1)) (min (u2 * l1) (u2 * u1)) \<le> x2 * x1 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   482
      x2 * x1 \<le> max (max (l2 * l1) (l2 * u1)) (max (u2 * l1) (u2 * u1))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   483
      by (rule zinterval_uneg)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   484
    thus ?thesis by (simp add: mult_ac min_commute max_commute min_min_commute max_max_commute)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   485
  qed
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   486
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   487
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   488
lemma zinterval_xnegupos: 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   489
assumes x1_lu : "l1 <= (x1::int) \<and> x1 <= u1"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   490
  and     x2_lu : "l2 <= (x2::int) \<and> x2 <= u2"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   491
  and     x1_neg: "x1 <= 0"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   492
  and     u1_pos: "0<= u1"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   493
  shows "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= x1 * x2 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   494
  \<and> x1 * x2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   495
proof -
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   496
  from x1_lu have mx1_lu : "-u1 <= -x1 \<and> -x1 <= -l1" by arith 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   497
  from u1_pos have mu1_neg : "-u1 <= 0" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   498
  from x1_neg have mx1_pos : "0 <= -x1" by simp
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   499
  with mx1_lu x2_lu mu1_neg
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   500
  have "min (min (- u1 * l2) (- u1 * u2)) (min (- l1 * l2) (- l1 * u2))
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   501
    \<le> - x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   502
    - x1 * x2 \<le> max (max (- u1 * l2) (- u1 * u2)) (max (- l1 * l2) (- l1 * u2))"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   503
    by (rule zinterval_lnegxpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   504
  moreover have "min (min (- u1 * l2) (- u1 * u2)) (min (- l1 * l2) (- l1 * u2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   505
    - max (max (u1 * l2) (u1 * u2)) (max (l1 * l2) (l1 * u2))" 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   506
    by (simp add: min_max_minus max_min_minus)
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   507
  moreover have "max (max (- u1 * l2) (- u1 * u2)) (max (- l1 * l2) (- l1 * u2)) =
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   508
    - min (min (u1 * l2) (u1 * u2)) (min (l1 * l2) (l1 * u2))" 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   509
    by (simp add: min_max_minus max_min_minus)
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   510
  ultimately have "- max (max (u1 * l2) (u1 * u2)) (max (l1 * l2) (l1 * u2)) \<le> - x1 * x2 \<and>
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   511
    - x1 * x2 \<le> - min (min (u1 * l2) (u1 * u2)) (min (l1 * l2) (l1 * u2))" 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   512
    by simp
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   513
  then show ?thesis by (simp add: mult_ac min_commute max_commute)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   514
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   515
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   516
lemma abs_mul: 
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   517
  assumes x1_lu: "l1 <= (x1::int) \<and> x1 <= u1"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   518
  and     x2_lu: "l2 <= (x2::int) \<and> x2 <= u2"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   519
  shows "min (min (l1*l2) (l1*u2)) (min (u1*l2) (u1*u2)) <= x1 * x2 
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   520
  \<and> x1 * x2 <= max (max (l1*l2) (l1*u2)) (max (u1*l2) (u1*u2))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   521
proof -
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   522
  have "(0 <= l1) \<or> (l1 <= 0 \<and> 0<= x1) \<or> (x1 <=0 \<and> 0 <= u1) \<or> (u1 <= 0)" 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   523
    by arith
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   524
  thus ?thesis
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   525
  proof (elim disjE conjE)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   526
    assume l1_pos: "0 <= l1"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   527
    with x1_lu x2_lu show ?thesis by (rule zinterval_lpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   528
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   529
    assume l1_neg: "l1 <= 0" and x1_pos: "0 <= x1"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   530
    with x1_lu x2_lu show ?thesis by (rule zinterval_lnegxpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   531
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   532
    assume x1_neg: "x1 <= 0" and u1_pos: "0 <= u1"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   533
    from x1_lu x2_lu x1_neg u1_pos show ?thesis by (rule zinterval_xnegupos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   534
  next
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   535
    assume u1_neg: "u1 <= 0"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   536
    with x1_lu x2_lu show ?thesis by (rule zinterval_uneg)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   537
  qed
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   538
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   539
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   540
lemma mult_x_mono_lpos : 
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   541
  assumes l_pos : "0 <= (l::int)"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   542
  and     x_lu : "l <= (x::int) \<and> x <= u"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   543
  shows "l*l <= x*x \<and> x*x <= u*u"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   544
proof -
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   545
  from x_lu have x_l : "l <= x" by arith
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   546
  from l_pos l_pos x_l x_l have xx_l : "l*l <= x*x"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   547
    by (rule zmult_mono)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   548
  moreover 
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   549
  from x_lu have x_u : "x <= u" by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   550
  from l_pos x_l have x_pos : "0 <= x" by arith
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   551
  from x_pos x_pos x_u x_u have xx_u : "x*x <= u*u"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   552
    by (rule zmult_mono)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   553
  ultimately show ?thesis by simp
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   554
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   555
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   556
lemma mult_x_mono_luneg : 
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   557
  assumes l_neg: "(l::int) <= 0"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   558
  and     u_neg: "u <= 0"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   559
  and     x_lu: "l <= (x::int) \<and> x <= u"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   560
  shows "u*u <= x*x \<and> x*x <= l*l"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   561
proof -
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   562
  from u_neg have "0<= -u" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   563
  moreover from x_lu have "-u <= -x \<and> -x <= -l" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   564
  ultimately have "- u * - u \<le> - x * - x \<and> - x * - x \<le> - l * - l"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   565
    by (rule mult_x_mono_lpos)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   566
  then show ?thesis by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   567
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   568
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   569
lemma mult_x_mono_lxnegupos : 
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   570
  assumes l_neg: "(l::int) <= 0"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   571
  and     u_pos: "0 <= u"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   572
  and     x_neg: "x <= 0"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   573
  and     x_lu: "l <= (x::int) \<and> x <= u"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   574
  shows "0 <= x*x \<and> x*x <= max (l*l) (u*u)"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   575
proof -
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   576
  have "(0::int) <= 0" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   577
  moreover from x_lu x_neg have "0 <= - x \<and> - x <= - l" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   578
  ultimately have "0 * 0 \<le> - x * - x \<and> - x * - x \<le> - l * - l" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   579
    by (rule mult_x_mono_lpos)
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   580
  then have xx_0ll : "0 <= x*x \<and> x*x <= l*l" by simp
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   581
  have "l*l <= max (l*l) (u*u)" by (simp add: le_maxI1)
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   582
  with xx_0ll show ?thesis by arith
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   583
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   584
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   585
lemma mult_x_mono_lnegupos : 
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   586
  assumes l_neg: "(l::int) <= 0"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   587
  and     u_pos: "0 <= u"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   588
  and     x_lu: "l <= (x::int) \<and> x <= u"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   589
  shows "0 <= x*x \<and> x*x <= max (l*l) (u*u)"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   590
proof -
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   591
  have "0 <= x \<or> x <= 0" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   592
  thus ?thesis
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   593
  proof
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   594
    assume x_neg: "x <= 0"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   595
    from l_neg u_pos x_neg x_lu show ?thesis by (rule mult_x_mono_lxnegupos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   596
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   597
    assume x_pos: "0 <= x"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   598
    from x_lu have mx_lu: "-u <= -x \<and> -x <= -l" by arith
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   599
    from x_pos have mx_neg: "-x <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   600
    from u_pos have mu_neg: "-u <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   601
    from x_lu x_pos have ml_pos: "0 <= -l" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   602
    from mu_neg ml_pos mx_neg mx_lu
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   603
    have "0 \<le> - x * - x \<and> - x * - x \<le> max (- u * - u) (- l * - l)"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   604
      by (rule mult_x_mono_lxnegupos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   605
    thus ?thesis by (simp add: max_commute)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   606
  qed
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   607
qed
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   608
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   609
lemma abs_mul_x:
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   610
  assumes x_lu: "l <= (x::int) \<and> x <= u"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   611
  shows
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   612
  "(if 0 <= l then l*l  else if u <= 0 then u*u else 0) <= x*x
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   613
  \<and> x*x <= (if 0 <= l then u*u  else if u <= 0 then l*l else (max (l*l) (u*u)))"
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   614
proof -
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   615
  have "(0 <= l) \<or> (l < 0 \<and> u <= 0) \<or> (l < 0 \<and> 0 < u)" by arith 
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   616
  thus ?thesis
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   617
  proof (elim disjE conjE)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   618
    assume l_pos: "0 <= l"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   619
    from l_pos have "(if 0 <= l then l*l  else if u <= 0 then u*u else 0) = l*l"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   620
      by simp
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   621
    moreover from l_pos have "(if 0 <= l then u*u  else if u <= 0 then l*l else (max (l*l) (u*u))) = u*u"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   622
      by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   623
    moreover from l_pos x_lu have "l * l \<le> x * x \<and> x * x \<le> u * u" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   624
      by (rule mult_x_mono_lpos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   625
    ultimately show ?thesis by simp 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   626
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   627
    assume l_neg: "l < 0" and u_neg: "u <= 0"  
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   628
    from l_neg have l_le0: "l <= 0" by simp
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   629
    from l_neg u_neg have "(if 0 <= l then l*l  else if u <= 0 then u*u else 0) = u*u"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   630
      by simp
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   631
    moreover
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   632
    from l_neg u_neg have "(if 0 <= l then u*u  else if u <= 0 then l*l else (max (l*l) (u*u))) = l*l"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   633
      by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   634
    moreover from l_le0 u_neg x_lu
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   635
    have "u * u \<le> x * x \<and> x * x \<le> l * l" 
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   636
      by (rule mult_x_mono_luneg)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   637
    ultimately show ?thesis by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   638
  next
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   639
    assume l_neg: "l < 0" and u_pos: "0 < u"
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   640
    from l_neg have l_le0: "l <= 0" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   641
    from u_pos have u_ge0: "0 <= u" by simp
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   642
    from l_neg u_pos have "(if 0 <= l then l*l  else if u <= 0 then u*u else 0) = 0"
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   643
      by simp
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   644
    moreover from l_neg u_pos have "(if 0 <= l then u*u else
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   645
      if u <= 0 then l*l else (max (l*l) (u*u))) = max (l*l) (u*u)" by simp
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   646
    moreover from l_le0 u_ge0 x_lu have "0 \<le> x * x \<and> x * x \<le> max (l * l) (u * u)" 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   647
      by (rule mult_x_mono_lnegupos)
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   648
    ultimately show ?thesis by simp 
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   649
  qed
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   650
qed
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   651
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   652
15239
fb73c8154b19 Tuned some proofs.
berghofe
parents: 15232
diff changeset
   653
use "barith.ML"
15232
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   654
setup Barith.setup
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   655
388a6f431d83 a very simple decision procedure for a fragment of bounded arithmetic
chaieb
parents:
diff changeset
   656
end