1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
|
(**************************************************************************)
(* *)
(* This file is part of Frama-C. *)
(* *)
(* Copyright (C) 2007-2010 *)
(* CEA (Commissariat l'nergie atomique et aux nergies *)
(* alternatives) *)
(* INRIA (Institut National de Recherche en Informatique et en *)
(* Automatique) *)
(* *)
(* you can redistribute it and/or modify it under the terms of the GNU *)
(* Lesser General Public License as published by the Free Software *)
(* Foundation, version 2.1. *)
(* *)
(* It is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
(* GNU Lesser General Public License for more details. *)
(* *)
(* See the GNU Lesser General Public License version v2.1 *)
(* for more details (enclosed in the file licenses/LGPLv2.1). *)
(* *)
(**************************************************************************)
(* Integer modulo definitions as in compcert integers*)
logic modul : int
axiom modul_pos : modul > 0
logic eqmod: int ,int -> prop
axiom eqmod_def :
forall x,y:int.
exists k:int. x =k*modul + y
axiom eqmod_refl :
forall x:int.
eqmod(x,x)
axiom eqmod_refl2 :
forall x,y:int.
x=y ->
eqmod(x,y)
axiom eqmod_sym :
forall x,y:int.
eqmod(x,y) ->
eqmod(y,x)
axiom eqmod_trans:
forall x,y,z:int.
eqmod(x,y) ->
eqmod(y,z) ->
eqmod(x,z)
axiom eqmod_small_eq :
forall x,y:int.
eqmod(x,y) ->
0<= x < modul ->
0<= y < modul ->
x=y
axiom eqmod_mod_eq:
forall x,y:int.
eqmod(x,y) ->
x % modul = y% modul
axiom eqmod_mod:
forall x:int.
eqmod(x,x %modul)
axiom eqmod_neg:
forall x,y:int.
eqmod(x,y) ->
eqmod(-x,-y)
axiom eqmod_add:
forall a,b,c,d:int.
eqmod(a,b) ->
eqmod(c,d) ->
eqmod(a+c,b+d)
axiom eqmod_sub:
forall a,b,c,d:int.
eqmod(a,b) ->
eqmod(c,d) ->
eqmod(a-c,b-d)
axiom eqmod_mult:
forall a,b,c,d:int.
eqmod(a,b) ->
eqmod(c,d) ->
eqmod(a*c,b*d)
axiom mod_in_range :
forall x:int.
0 <= x%modul < modul
(* integer definition *)
type Int
logic intval : Int -> int (* Z representation of the int *)
logic intrange : Int -> prop (* range property of the int vs a modul *)
logic unsigned : Int -> int
logic signed : Int -> int
logic repr : int -> Int
logic Int_eq : Int equality
logic half_modul : int
logic max_unsigned : int
logic max_signed : int
logic min_signed : int
axiom half_modul_value : half_modul = modul /2
axiom max_unsigned_value : max_signed = modul - 1
axiom max_signed_value : max_signed = half_modul - 1
axiom min_signed_value : min_signed =- half_modul
axiom unsigned_def :
forall i:Int.
unsigned(i) = intval(i)
axiom signed_lt :
forall i:Int.
intval(i) < half_modul ->
signed(i) = unsigned(i)
axiom signed_ge :
forall i:Int.
intval(i) >= half_modul ->
signed(i) = unsigned(i) - modul
axiom mod_in_range :
forall x:Int. 0 <= (intval(x))%modul < modul
axiom repr_intval :
forall x:int. intval(repr(x))=x
axiom repr_intrange :
forall x:int. intrange(repr(x))
logic zero : Int
logic one : Int
logic mone : Int
axiom zero_def : zero = repr(0)
axiom one_def : one = repr(1)
axiom mone_def : mone = repr(-1)
(** coercions between int and Int **)
axiom eqm_unsigned_repr :
forall z:int. eqmod(z,unsigned(repr(z)))
axiom eqm_unsigned_repr_l :
forall a,b:int.
eqmod(a,b) ->
eqmod(unsigned(repr(a)),b)
axiom eqm_unsigned_repr_r :
forall a,b:int.
eqmod(a,b) ->
eqmod(a,unsigned(repr(b)))
axiom eqm_signed_unsigned :
forall x:Int.
eqmod(signed(x),unsigned(x))
axiom unsigned_range:
forall i:Int. 0 <= unsigned(i) < max_unsigned
axiom unsigned_range_2:
forall i:Int. 0 <= unsigned(i) <= max_unsigned
(** boolean intepretation **)
axiom is_true :
forall i: Int. i <> zero
axiom is_false :
forall i:Int. i = zero
(** arithmetics operations **)
(** comparisons definition **)
logic cmpi_eq : Int,Int -> Int
logic cmpi_lt : Int,Int -> Int
logic cmpi_ltu : Int,Int -> Int
axiom cmpi_eq_def_true:
forall x,y:Int.
unsigned(x) = unsigned(y) ->
cmpi_eq(x,y) = one
axiom cmpi_eq_def_false:
forall x,y:Int.
unsigned(x) <> unsigned(y) ->
cmpi_eq(x,y) = zero
axiom cmpi_lt_def_true :
forall x,y:Int.
signed(x) < signed(y) ->
cmpi_lt(x,y) = one
axiom cmpi_lt_def_false :
forall x,y:Int.
signed(x) >= signed(y) ->
cmpi_lt(x,y) = zero
axiom cmpi_ltu_def_true :
forall x,y:Int.
unsigned(x) < unsigned(y) ->
cmpi_lt(x,y) = one
axiom cmpi_ltu_def_false :
forall x,y:Int.
unsigned(x) >= unsigned(y) ->
cmpi_lt(x,y) = zero
(** negation of a Int definition and properties **)
logic i_neg: Int -> Int
axiom neg_def :
forall i:Int. i_neg(i) = repr(-unsigned(i))
axiom neg_repr :
forall i:int . i_neg(repr(i)) = repr(-i)
axiom neg_zero :
i_neg(zero) = zero
axiom neg_involutive :
forall i:Int. i_neg (i_neg(i)) = i
(** addition of int definition and properties **)
logic i_add : Int,Int -> Int
axiom i_add_unsigned :
forall x,y:Int.
i_add(x,y) = repr (unsigned(x)+unsigned(y))
axiom add_signed :
forall x,y:Int.
i_add(x,y) = repr(signed(x)+signed(y))
axiom add_commut :
forall x,y:Int.
i_add(x,y) = i_add(y,x)
axiom add_permut :
forall x,y,z:Int.
i_add(x,i_add(y,z)) = i_add(y,i_add(x,z))
axiom add_neg_zero :
forall x:Int. i_add(x,i_neg(x)) = zero
axiom neg_add_distr :
forall x,y:Int.
i_neg(i_add(x,y)) = i_add (i_neg(x),i_neg(y))
(** subtraction of Int definition and properties **)
logic i_sub : Int,Int -> Int
axiom i_sub_def :
forall x,y:Int.
i_sub(x,y) = repr (unsigned(x)-unsigned(y))
axiom sub_zero_l :
forall x:Int. i_sub(x,zero) = x
axiom sub_zero_r :
forall x:Int. i_sub(zero,x) = i_neg(x)
axiom sub_add_opp :
forall x,y:Int. i_sub(x,y) = i_add(x,i_neg(y))
axiom sub_idem :
forall x:Int. i_sub(x,x) = zero
axiom sub_add_l :
forall x,y,z:Int. i_sub (i_add(x,y),z) = i_add(i_sub(x,z),y)
axiom sub_add_r:
forall x,y,z:Int. i_sub(x,i_add(y,z)) = i_add(i_sub(x,z),i_neg(y))
axiom sub_shifted:
forall x,y,z:Int. i_sub(i_add(x,z),i_add(y,z)) =i_sub(x,y)
(** multiplication of Int definition and properties **)
logic i_mul : Int,Int -> Int
axiom i_mul_def :
forall x,y:Int.
i_mul(x,y) = repr (unsigned(x)*unsigned(y))
axiom mul_commut:
forall x,y:Int. i_mul(x,y) = i_mul(y,x)
axiom mul_zero:
forall x:Int. i_mul(x,zero) = zero
axiom mul_one:
forall x:Int. i_mul(x,one) = x
axiom mul_assoc:
forall x,y,z:Int. i_mul(i_mul(x,y),z) = i_mul(x,i_mul(y,z))
axiom mul_add_distr_l :
forall x,y,z:Int. i_mul(i_add(x,y),z) = i_add(i_mul(x,z),i_mul(y,z))
axiom mul_add_distr_r :
forall x,y,z:Int. i_mul(x,i_add(y,z)) = i_add(i_mul(x,y),i_mul(x,z))
axiom neg_mul_distr_l:
forall x,y:Int. i_neg(i_mul(x,y)) = i_mul (i_neg(x),y)
axiom neg_mul_distr_l:
forall x,y:Int. i_neg(i_mul(x,y)) = i_mul (x,i_neg(y))
(** divisions on signed Int definition and properties **)
logic divs:Int,Int -> Int
axiom divs_neg_neg :
forall x,y:Int.
signed(x) < 0 ->
signed(y) < 0 ->
divs(x,y) = repr (-signed(x)/(-signed(y)))
axiom divs_neg_pos :
forall x,y:Int.
signed(x) < 0 ->
signed(y) >= 0 ->
divs(x,y) = repr (-((-signed(x))/signed(y)))
axiom divs_pos_neg :
forall x,y:Int.
signed(x)>= 0 ->
signed(y) < 0 ->
divs(x,y) = repr(-(signed(x)/(-signed(y))))
axiom divs_pos_pos :
forall x,y:Int.
signed(x)>= 0 ->
signed(y)>= 0 ->
divs(x,y) = repr (signed(x)/signed(y))
(** divisions of unsigned Int definition and properties **)
logic divu : Int,Int -> Int
axiom divu_def :
forall x,y:Int. divu(x,y) = repr (unsigned(x)/unsigned(y))
(** Modulo of signed Int definition and properties **)
logic mods :Int,Int -> Int
axiom mods_neg_neg:
forall x,y:Int.
signed(x) < 0 ->
signed(y) < 0 ->
mods(x,y) = repr (signed(x)-(((-signed(x))/(-signed(y)))*signed(y)))
axiom divs_neg_pos :
forall x,y:Int.
signed(x) < 0 ->
signed(y) >= 0 ->
mods(x,y) = repr (signed(x) +(((-signed(x))/signed(y))*signed(y)))
axiom divs_pos_neg :
forall x,y:Int.
signed(x)>= 0 ->
signed(y) < 0 ->
mods(x,y) = repr(signed(x)+((signed(x)/(-signed(y)))*signed(y)))
axiom divs_pos_pos :
forall x,y:Int.
signed(x)>= 0 ->
signed(y)>= 0 ->
divs(x,y) = repr(signed(x)-((signed(x)/signed(y))*signed(y)))
(** Modulo of unsigned Int definition and properties **)
logic modu:Int,Int ->Int
axiom modu_def:
forall x,y:Int. modu(x,y)=repr (unsigned(x)%unsigned(y))
|