effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
FStar.Pervasives.Lemma
val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b )
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow2_modulo_modulo_lemma_1 a b c = pow2_plus (c - b) b; modulo_modulo_lemma a (pow2 b) (pow2 (c - b))
val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b ) let pow2_modulo_modulo_lemma_1 a b c =
false
null
true
pow2_plus (c - b) b; modulo_modulo_lemma a (pow2 b) (pow2 (c - b))
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Math.Lemmas.modulo_modulo_lemma", "Prims.pow2", "Prims.op_Subtraction", "Prims.unit", "FStar.Math.Lemmas.pow2_plus" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c) val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 ) let pow2_multiplication_modulo_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c ) let pow2_multiplication_modulo_lemma_2 a b c = calc (==) { (a * pow2 c) % pow2 b; == {} (a * pow2 c) % pow2 (c + (b-c)); == { pow2_plus c (b-c) } (a * pow2 c) % (pow2 c * pow2 (b-c)); == { modulo_scale_lemma a (pow2 c) (pow2 (b-c)) } (a % pow2 (b - c)) * pow2 c; } val pow2_modulo_division_lemma_1: a:nat -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) / pow2 b = (a / pow2 b) % (pow2 (c - b)) ) let pow2_modulo_division_lemma_1 a b c = pow2_plus (c - b) b; modulo_division_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) / pow2 b = 0 ) let pow2_modulo_division_lemma_2 a b c = pow2_le_compat b c; small_division_lemma_1 (a % pow2 c) (pow2 b) val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b )
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b )
[]
FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.nat -> c: Prims.nat{c >= b} -> FStar.Pervasives.Lemma (ensures a % Prims.pow2 c % Prims.pow2 b = a % Prims.pow2 b)
{ "end_col": 47, "end_line": 867, "start_col": 2, "start_line": 866 }
FStar.Pervasives.Lemma
val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; }
val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p =
false
null
true
calc ( == ) { ((a + b) * c) % p; ( == ) { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; ( == ) { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; ( == ) { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.modulo_distributivity" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p)
[]
FStar.Math.Lemmas.lemma_mod_plus_mul_distr
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> c: Prims.int -> p: Prims.pos -> FStar.Pervasives.Lemma (ensures (a + b) * c % p = ((a % p + b % p) % p) * (c % p) % p)
{ "end_col": 3, "end_line": 621, "start_col": 2, "start_line": 613 }
FStar.Pervasives.Lemma
val modulo_sub_lemma (a : int) (b : nat) (c : pos) : Lemma (requires (b < c /\ (a - b) % c = 0)) (ensures (b = a % c))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modulo_sub_lemma a b c = calc (==) { b; == { modulo_lemma b c } b % c; == { lemma_mod_twice b c } (b%c) % c; == { (* hyp *) } (b%c + (a-b)%c) % c; == { modulo_distributivity b (a-b) c } (b+(a-b)) % c; == {} a % c; }
val modulo_sub_lemma (a : int) (b : nat) (c : pos) : Lemma (requires (b < c /\ (a - b) % c = 0)) (ensures (b = a % c)) let modulo_sub_lemma a b c =
false
null
true
calc ( == ) { b; ( == ) { modulo_lemma b c } b % c; ( == ) { lemma_mod_twice b c } (b % c) % c; ( == ) { () } (b % c + (a - b) % c) % c; ( == ) { modulo_distributivity b (a - b) c } (b + (a - b)) % c; ( == ) { () } a % c; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.nat", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "Prims.op_Subtraction", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.modulo_lemma", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_twice", "FStar.Math.Lemmas.modulo_distributivity" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c) val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 ) let pow2_multiplication_modulo_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c ) let pow2_multiplication_modulo_lemma_2 a b c = calc (==) { (a * pow2 c) % pow2 b; == {} (a * pow2 c) % pow2 (c + (b-c)); == { pow2_plus c (b-c) } (a * pow2 c) % (pow2 c * pow2 (b-c)); == { modulo_scale_lemma a (pow2 c) (pow2 (b-c)) } (a % pow2 (b - c)) * pow2 c; } val pow2_modulo_division_lemma_1: a:nat -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) / pow2 b = (a / pow2 b) % (pow2 (c - b)) ) let pow2_modulo_division_lemma_1 a b c = pow2_plus (c - b) b; modulo_division_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) / pow2 b = 0 ) let pow2_modulo_division_lemma_2 a b c = pow2_le_compat b c; small_division_lemma_1 (a % pow2 c) (pow2 b) val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b ) let pow2_modulo_modulo_lemma_1 a b c = pow2_plus (c - b) b; modulo_modulo_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 c ) let pow2_modulo_modulo_lemma_2 a b c = pow2_le_compat b c; small_modulo_lemma_1 (a % pow2 c) (pow2 b) val modulo_add : p:pos -> a:int -> b:int -> c:int -> Lemma (requires (b % p = c % p)) (ensures ((a + b) % p = (a + c) % p)) let modulo_add p a b c = modulo_distributivity a b p; modulo_distributivity a c p val lemma_mod_twice : a:int -> p:pos -> Lemma ((a % p) % p == a % p) let lemma_mod_twice a p = lemma_mod_mod (a % p) a p val modulo_sub : p:pos -> a:int -> b:int -> c:int -> Lemma (requires ((a + b) % p = (a + c) % p)) (ensures (b % p = c % p)) let modulo_sub p a b c = modulo_add p (-a) (a + b) (a + c) val mod_add_both (a:int) (b:int) (x:int) (n:pos) : Lemma (requires a % n == b % n) (ensures (a + x) % n == (b + x) % n) let mod_add_both (a:int) (b:int) (x:int) (n:pos) = calc (==) { (a + x) % n; == { modulo_distributivity a x n } ((a % n) + (x % n)) % n; == { (* hyp *) } ((b % n) + (x % n)) % n; == { modulo_distributivity b x n } (b + x) % n; } val lemma_mod_plus_injective (n:pos) (a:int) (b:nat) (c:nat) : Lemma (requires b < n /\ c < n /\ (a + b) % n = (a + c) % n) (ensures b = c) let lemma_mod_plus_injective (n:pos) (a:int) (b:nat) (c:nat) = small_mod b n; small_mod c n; mod_add_both (a + b) (a + c) (-a) n (* Another characterization of the modulo *) val modulo_sub_lemma (a : int) (b : nat) (c : pos) : Lemma (requires (b < c /\ (a - b) % c = 0)) (ensures (b = a % c))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modulo_sub_lemma (a : int) (b : nat) (c : pos) : Lemma (requires (b < c /\ (a - b) % c = 0)) (ensures (b = a % c))
[]
FStar.Math.Lemmas.modulo_sub_lemma
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.nat -> c: Prims.pos -> FStar.Pervasives.Lemma (requires b < c /\ (a - b) % c = 0) (ensures b = a % c)
{ "end_col": 3, "end_line": 932, "start_col": 2, "start_line": 920 }
FStar.Pervasives.Lemma
val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; }
val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a: int) (b n: pos) =
false
null
true
calc ( == ) { (a / b) % n; ( == ) { lemma_div_mod a (b * n) } (((b * n) * (a / (b * n))) / b) % n; ( == ) { paren_mul_right b n (a / (b * n)) } ((b * (n * (a / (b * n)))) / b) % n; ( == ) { cancel_mul_div (n * (a / (b * n))) b } (n * (a / (b * n))) % n; ( == ) { cancel_mul_mod (a / (b * n)) n } 0; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "Prims.op_Division", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_mod", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.cancel_mul_div", "FStar.Math.Lemmas.cancel_mul_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0)
[]
FStar.Math.Lemmas.mod_mul_div_exact
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.pos -> n: Prims.pos -> FStar.Pervasives.Lemma (requires a % (b * n) == 0) (ensures a / b % n == 0)
{ "end_col": 3, "end_line": 665, "start_col": 2, "start_line": 655 }
FStar.Pervasives.Lemma
val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c )
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow2_multiplication_modulo_lemma_2 a b c = calc (==) { (a * pow2 c) % pow2 b; == {} (a * pow2 c) % pow2 (c + (b-c)); == { pow2_plus c (b-c) } (a * pow2 c) % (pow2 c * pow2 (b-c)); == { modulo_scale_lemma a (pow2 c) (pow2 (b-c)) } (a % pow2 (b - c)) * pow2 c; }
val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c ) let pow2_multiplication_modulo_lemma_2 a b c =
false
null
true
calc ( == ) { (a * pow2 c) % pow2 b; ( == ) { () } (a * pow2 c) % pow2 (c + (b - c)); ( == ) { pow2_plus c (b - c) } (a * pow2 c) % (pow2 c * pow2 (b - c)); ( == ) { modulo_scale_lemma a (pow2 c) (pow2 (b - c)) } (a % pow2 (b - c)) * pow2 c; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.modulo_scale_lemma" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c) val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 ) let pow2_multiplication_modulo_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c )
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c )
[]
FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.nat -> c: Prims.nat{c <= b} -> FStar.Pervasives.Lemma (ensures a * Prims.pow2 c % Prims.pow2 b = (a % Prims.pow2 (b - c)) * Prims.pow2 c)
{ "end_col": 3, "end_line": 849, "start_col": 2, "start_line": 841 }
FStar.Pervasives.Lemma
val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; }
val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a b: int) (n: pos) =
false
null
true
calc ( == ) { (a - b % n) % n; ( == ) { lemma_mod_plus (a - (b % n)) (- (b / n)) n } (a - b % n + n * (- (b / n))) % n; ( == ) { neg_mul_right n (b / n) } (a - b % n - n * (b / n)) % n; ( == ) { lemma_div_mod b n } (a - b) % n; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.op_Addition", "Prims.op_Minus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.squash", "FStar.Math.Lemmas.neg_mul_right", "FStar.Math.Lemmas.lemma_div_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n)
[]
FStar.Math.Lemmas.lemma_mod_sub_distr
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures (a - b % n) % n = (a - b) % n)
{ "end_col": 3, "end_line": 389, "start_col": 2, "start_line": 381 }
FStar.Pervasives.Lemma
val mod_add_both (a:int) (b:int) (x:int) (n:pos) : Lemma (requires a % n == b % n) (ensures (a + x) % n == (b + x) % n)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mod_add_both (a:int) (b:int) (x:int) (n:pos) = calc (==) { (a + x) % n; == { modulo_distributivity a x n } ((a % n) + (x % n)) % n; == { (* hyp *) } ((b % n) + (x % n)) % n; == { modulo_distributivity b x n } (b + x) % n; }
val mod_add_both (a:int) (b:int) (x:int) (n:pos) : Lemma (requires a % n == b % n) (ensures (a + x) % n == (b + x) % n) let mod_add_both (a b x: int) (n: pos) =
false
null
true
calc ( == ) { (a + x) % n; ( == ) { modulo_distributivity a x n } ((a % n) + (x % n)) % n; ( == ) { () } ((b % n) + (x % n)) % n; ( == ) { modulo_distributivity b x n } (b + x) % n; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.modulo_distributivity", "Prims.squash" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c) val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 ) let pow2_multiplication_modulo_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c ) let pow2_multiplication_modulo_lemma_2 a b c = calc (==) { (a * pow2 c) % pow2 b; == {} (a * pow2 c) % pow2 (c + (b-c)); == { pow2_plus c (b-c) } (a * pow2 c) % (pow2 c * pow2 (b-c)); == { modulo_scale_lemma a (pow2 c) (pow2 (b-c)) } (a % pow2 (b - c)) * pow2 c; } val pow2_modulo_division_lemma_1: a:nat -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) / pow2 b = (a / pow2 b) % (pow2 (c - b)) ) let pow2_modulo_division_lemma_1 a b c = pow2_plus (c - b) b; modulo_division_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) / pow2 b = 0 ) let pow2_modulo_division_lemma_2 a b c = pow2_le_compat b c; small_division_lemma_1 (a % pow2 c) (pow2 b) val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b ) let pow2_modulo_modulo_lemma_1 a b c = pow2_plus (c - b) b; modulo_modulo_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 c ) let pow2_modulo_modulo_lemma_2 a b c = pow2_le_compat b c; small_modulo_lemma_1 (a % pow2 c) (pow2 b) val modulo_add : p:pos -> a:int -> b:int -> c:int -> Lemma (requires (b % p = c % p)) (ensures ((a + b) % p = (a + c) % p)) let modulo_add p a b c = modulo_distributivity a b p; modulo_distributivity a c p val lemma_mod_twice : a:int -> p:pos -> Lemma ((a % p) % p == a % p) let lemma_mod_twice a p = lemma_mod_mod (a % p) a p val modulo_sub : p:pos -> a:int -> b:int -> c:int -> Lemma (requires ((a + b) % p = (a + c) % p)) (ensures (b % p = c % p)) let modulo_sub p a b c = modulo_add p (-a) (a + b) (a + c) val mod_add_both (a:int) (b:int) (x:int) (n:pos) : Lemma (requires a % n == b % n) (ensures (a + x) % n == (b + x) % n)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mod_add_both (a:int) (b:int) (x:int) (n:pos) : Lemma (requires a % n == b % n) (ensures (a + x) % n == (b + x) % n)
[]
FStar.Math.Lemmas.mod_add_both
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> x: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (requires a % n == b % n) (ensures (a + x) % n == (b + x) % n)
{ "end_col": 3, "end_line": 904, "start_col": 2, "start_line": 896 }
FStar.Pervasives.Lemma
val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; }
val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c =
false
null
true
calc ( == ) { a * (b + c); ( == ) { () } (b + c) * a; ( == ) { distributivity_add_left b c a } b * a + c * a; ( == ) { () } a * b + a * c; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Mul.op_Star", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_left" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c)
[]
FStar.Math.Lemmas.distributivity_add_right
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> c: Prims.int -> FStar.Pervasives.Lemma (ensures a * (b + c) = a * b + a * c)
{ "end_col": 3, "end_line": 89, "start_col": 2, "start_line": 81 }
FStar.Pervasives.Lemma
val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow2_le_compat n m = if m < n then pow2_lt_compat n m
val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m =
false
null
true
if m < n then pow2_lt_compat n m
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.op_LessThan", "FStar.Math.Lemmas.pow2_lt_compat", "Prims.bool", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n))
[]
FStar.Math.Lemmas.pow2_le_compat
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n: Prims.nat -> m: Prims.nat -> FStar.Pervasives.Lemma (requires m <= n) (ensures Prims.pow2 m <= Prims.pow2 n)
{ "end_col": 34, "end_line": 245, "start_col": 2, "start_line": 245 }
FStar.Pervasives.Lemma
val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow2_double_mult n = pow2_double_sum n
val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n =
false
null
true
pow2_double_sum n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "FStar.Math.Lemmas.pow2_double_sum", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = ()
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1))
[]
FStar.Math.Lemmas.pow2_double_mult
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n: Prims.nat -> FStar.Pervasives.Lemma (ensures 2 * Prims.pow2 n = Prims.pow2 (n + 1))
{ "end_col": 42, "end_line": 229, "start_col": 25, "start_line": 229 }
FStar.Pervasives.Lemma
val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n
val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n =
false
null
true
lemma_mod_plus a (- 1) n; lemma_div_plus a (- 1) n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_div_plus", "Prims.op_Minus", "Prims.unit", "FStar.Math.Lemmas.lemma_mod_plus" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1)
[]
FStar.Math.Lemmas.sub_div_mod_1
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures (a - n) % n == a % n /\ (a - n) / n == a / n - 1)
{ "end_col": 27, "end_line": 355, "start_col": 4, "start_line": 354 }
FStar.Pervasives.Lemma
val lemma_div_mod_plus (a k: int) (n: pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n
val lemma_div_mod_plus (a k: int) (n: pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) let lemma_div_mod_plus (a k: int) (n: pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) =
false
null
true
lemma_div_plus a k n; lemma_mod_plus a k n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.unit", "FStar.Math.Lemmas.lemma_div_plus", "Prims.l_True", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.op_Division", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.op_Modulus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_div_mod_plus (a k: int) (n: pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n)
[]
FStar.Math.Lemmas.lemma_div_mod_plus
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> k: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures (a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n)
{ "end_col": 24, "end_line": 345, "start_col": 4, "start_line": 344 }
FStar.Pervasives.Lemma
val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n
val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a: int) (n: pos) =
false
null
true
small_mod 0 n; lemma_mod_plus 0 a n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.unit", "FStar.Math.Lemmas.small_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0)
[]
FStar.Math.Lemmas.cancel_mul_mod
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures a * n % n == 0)
{ "end_col": 22, "end_line": 367, "start_col": 2, "start_line": 366 }
FStar.Pervasives.Lemma
val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; }
val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c =
false
null
true
calc ( == ) { (a - b) * c; ( == ) { () } (a + (- b)) * c; ( == ) { distributivity_add_left a (- b) c } a * c + (- b) * c; ( == ) { neg_mul_left b c } a * c - b * c; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "Prims.op_Minus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.neg_mul_left" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c)
[]
FStar.Math.Lemmas.distributivity_sub_left
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> c: Prims.int -> FStar.Pervasives.Lemma (ensures (a - b) * c = a * c - b * c)
{ "end_col": 3, "end_line": 153, "start_col": 2, "start_line": 145 }
FStar.Pervasives.Lemma
val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mul_sub_distr a b c = distributivity_sub_right a b c
val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c =
false
null
true
distributivity_sub_right a b c
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "FStar.Math.Lemmas.distributivity_sub_right", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c))
[]
FStar.Math.Lemmas.lemma_mul_sub_distr
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> c: Prims.int -> FStar.Pervasives.Lemma (ensures a * b - a * c = a * (b - c))
{ "end_col": 32, "end_line": 445, "start_col": 2, "start_line": 445 }
FStar.Pervasives.Lemma
val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; }
val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c =
false
null
true
calc ( == ) { a * (b - c); ( == ) { () } a * (b + (- c)); ( == ) { distributivity_add_right a b (- c) } a * b + a * (- c); ( == ) { neg_mul_right a c } a * b - a * c; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "Prims.op_Minus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_right", "FStar.Math.Lemmas.neg_mul_right" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c))
[]
FStar.Math.Lemmas.distributivity_sub_right
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> c: Prims.int -> FStar.Pervasives.Lemma (ensures a * (b - c) = a * b - a * c)
{ "end_col": 3, "end_line": 167, "start_col": 2, "start_line": 159 }
FStar.Pervasives.Lemma
val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let div_exact_r (a:int) (n:pos) = lemma_div_exact a n
val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a: int) (n: pos) =
false
null
true
lemma_div_exact a n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_div_exact", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n))
[]
FStar.Math.Lemmas.div_exact_r
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (requires a % n = 0) (ensures a = (a / n) * n)
{ "end_col": 53, "end_line": 455, "start_col": 34, "start_line": 455 }
FStar.Pervasives.Lemma
val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p
val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p =
false
null
true
lemma_mod_plus_distr_l b a p
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_mod_plus_distr_l", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p)
[]
FStar.Math.Lemmas.lemma_mod_plus_distr_r
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> p: Prims.pos -> FStar.Pervasives.Lemma (ensures (a + b) % p = (a + b % p) % p)
{ "end_col": 30, "end_line": 490, "start_col": 2, "start_line": 490 }
FStar.Pervasives.Lemma
val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; }
val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a b: int) (n: pos) =
false
null
true
calc ( == ) { (a * b) % n; ( == ) { swap_mul a b } (b * a) % n; ( == ) { lemma_mod_mul_distr_l b a n } ((b % n) * a) % n; ( == ) { swap_mul a (b % n) } (a * (b % n)) % n; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.swap_mul", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_l" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n)
[]
FStar.Math.Lemmas.lemma_mod_mul_distr_r
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures a * b % n = a * (b % n) % n)
{ "end_col": 3, "end_line": 435, "start_col": 2, "start_line": 427 }
FStar.Pervasives.Lemma
val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p
val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p =
false
null
true
lemma_mod_lt b p; modulo_lemma (b % p) p
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.modulo_lemma", "Prims.op_Modulus", "Prims.unit", "FStar.Math.Lemmas.lemma_mod_lt" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p))
[]
FStar.Math.Lemmas.lemma_mod_mod
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> p: Prims.pos -> FStar.Pervasives.Lemma (requires a = b % p) (ensures a % p = b % p)
{ "end_col": 24, "end_line": 497, "start_col": 2, "start_line": 496 }
FStar.Pervasives.Lemma
val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; }
val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p =
false
null
true
calc ( == ) { (a % p) + ((a - (a % p)) / p) * p; ( == ) { lemma_mod_spec a p } (a % p) + (a / p) * p; ( == ) { lemma_div_mod a p } a; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Addition", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_spec", "Prims.squash", "FStar.Math.Lemmas.lemma_div_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p)
[]
FStar.Math.Lemmas.lemma_mod_spec2
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> p: Prims.pos -> FStar.Pervasives.Lemma (ensures (let q = (a - a % p) / p in a = a % p + q * p))
{ "end_col": 3, "end_line": 478, "start_col": 2, "start_line": 472 }
FStar.Pervasives.Lemma
val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n
val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a: int) (n: nonzero) =
false
null
true
cancel_mul_div a n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.nonzero", "FStar.Math.Lemmas.cancel_mul_div", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a)
[]
FStar.Math.Lemmas.multiple_division_lemma
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> n: Prims.nonzero -> FStar.Pervasives.Lemma (ensures a * n / n = a)
{ "end_col": 68, "end_line": 564, "start_col": 50, "start_line": 564 }
FStar.Pervasives.Lemma
val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p
val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p =
false
null
true
let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.op_Addition", "Prims.op_Modulus", "Prims.unit", "FStar.Math.Lemmas.lemma_mod_spec2", "Prims.op_Division", "Prims.op_Subtraction" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p)
[]
FStar.Math.Lemmas.lemma_mod_plus_distr_l
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> p: Prims.pos -> FStar.Pervasives.Lemma (ensures (a + b) % p = (a % p + b) % p)
{ "end_col": 32, "end_line": 485, "start_col": 34, "start_line": 482 }
FStar.Pervasives.Lemma
val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n
val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a k: int) (n: pos) =
false
null
true
calc ( == ) { n * ((a + k * n) / n - a / n); ( == ) { distributivity_sub_right n ((a + k * n) / n) (a / n) } n * ((a + k * n) / n) - n * (a / n); ( == ) { (lemma_div_mod (a + k * n) n; lemma_div_mod a n) } (a + k * n - (a + k * n) % n) - (a - a % n); ( == ) { () } k * n - (a + k * n) % n + a % n; ( == ) { lemma_mod_plus a k n } k * n; }; lemma_cancel_mul ((a + k * n) / n - a / n) k n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_cancel_mul", "Prims.op_Subtraction", "Prims.op_Division", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.unit", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Modulus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.distributivity_sub_right", "Prims.squash", "FStar.Math.Lemmas.lemma_div_mod", "FStar.Math.Lemmas.lemma_mod_plus" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k)
[]
FStar.Math.Lemmas.lemma_div_plus
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> k: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures (a + k * n) / n = a / n + k)
{ "end_col": 40, "end_line": 340, "start_col": 2, "start_line": 329 }
FStar.Pervasives.Lemma
val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; }
val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b =
false
null
true
calc ( == ) { (- a) % b; ( == ) { lemma_mod_plus (- a) 1 b } ((- a) + 1 * b) % b; ( == ) { () } (b - a) % b; ( == ) { small_mod (b - a) b } b - a; ( == ) { small_mod a b } b - a % b; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Modulus", "Prims.op_Minus", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.squash", "FStar.Math.Lemmas.small_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b))
[]
FStar.Math.Lemmas.lemma_mod_sub_1
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.pos -> b: Prims.pos{a < b} -> FStar.Pervasives.Lemma (ensures (- a) % b = b - a % b)
{ "end_col": 3, "end_line": 406, "start_col": 2, "start_line": 396 }
FStar.Pervasives.Lemma
val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b
val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m =
false
null
true
division_propriety a b; multiplication_order_lemma (a / b + 1) m b
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "FStar.Math.Lemmas.multiplication_order_lemma", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "FStar.Math.Lemmas.division_propriety" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1)
[]
FStar.Math.Lemmas.division_definition_lemma_2
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.pos -> m: Prims.int{m * b <= a} -> FStar.Pervasives.Lemma (ensures m < a / b + 1)
{ "end_col": 44, "end_line": 553, "start_col": 2, "start_line": 552 }
FStar.Pervasives.Lemma
val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; ()
val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a k: int) (n: pos) =
false
null
true
calc ( == ) { (a + k * n) % n - a % n; ( == ) { (lemma_div_mod a n; lemma_div_mod (a + k * n) n) } ((a + k * n) - n * ((a + k * n) / n)) - (a - n * (a / n)); ( == ) { () } n * k + n * (a / n) - n * ((a + k * n) / n); ( == ) { (distributivity_add_right n k (a / n); distributivity_sub_right n (k + a / n) ((a + k * n) / n)) } n * (k + a / n - (a + k * n) / n); }; lt_multiple_is_equal ((a + k * n) % n) (a % n) (k + a / n - (a + k * n) / n) n; ()
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "Prims.unit", "FStar.Math.Lemmas.lt_multiple_is_equal", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.op_Division", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_mod", "Prims.squash", "FStar.Math.Lemmas.distributivity_sub_right", "FStar.Math.Lemmas.distributivity_add_right" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n)
[]
FStar.Math.Lemmas.lemma_mod_plus
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> k: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures (a + k * n) % n = a % n)
{ "end_col": 4, "end_line": 325, "start_col": 2, "start_line": 314 }
FStar.Pervasives.Lemma
val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; }
val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n =
false
null
true
calc ( == ) { (a * b) % n; ( == ) { lemma_div_mod a n } ((n * (a / n) + a % n) * b) % n; ( == ) { distributivity_add_left (n * (a / n)) (a % n) b } ((n * (a / n)) * b + (a % n) * b) % n; ( == ) { (paren_mul_right n (a / n) b; swap_mul ((a / n) * b) n) } ((a % n) * b + ((a / n) * b) * n) % n; ( == ) { lemma_mod_plus ((a % n) * b) ((a / n) * b) n } ((a % n) * b) % n; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "Prims.op_Division", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_mod", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.swap_mul", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.lemma_mod_plus" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n)
[]
FStar.Math.Lemmas.lemma_mod_mul_distr_l
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures a * b % n = (a % n) * b % n)
{ "end_col": 3, "end_line": 423, "start_col": 2, "start_line": 413 }
FStar.Pervasives.Lemma
val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n )
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n)
val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n =
false
null
true
division_definition (a + n * b) b (a / b + n)
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.division_definition", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int ->
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n )
[]
FStar.Math.Lemmas.division_addition_lemma
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.pos -> n: Prims.int -> FStar.Pervasives.Lemma (ensures (a + n * b) / b = a / b + n)
{ "end_col": 81, "end_line": 573, "start_col": 36, "start_line": 573 }
FStar.Pervasives.Lemma
val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n
val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a: int) (n: pos) =
false
null
true
cancel_mul_mod a n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.cancel_mul_mod", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0)
[]
FStar.Math.Lemmas.multiple_modulo_lemma
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures a * n % n = 0)
{ "end_col": 62, "end_line": 568, "start_col": 44, "start_line": 568 }
FStar.Pervasives.Lemma
val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n
val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a: int) (n: pos) (b: int) =
false
null
true
neg_mul_left b n; lemma_mod_plus a (- b) n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.op_Minus", "Prims.unit", "FStar.Math.Lemmas.neg_mul_left" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n)
[]
FStar.Math.Lemmas.lemma_mod_sub
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> n: Prims.pos -> b: Prims.int -> FStar.Pervasives.Lemma (ensures (a - b * n) % n = a % n)
{ "end_col": 25, "end_line": 631, "start_col": 2, "start_line": 630 }
FStar.Pervasives.Lemma
val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; }
val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c =
false
null
true
calc ( == ) { (a + b) % c; ( == ) { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; ( == ) { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_plus_distr_l", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_plus_distr_r" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c)
[]
FStar.Math.Lemmas.modulo_distributivity
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> c: Prims.pos -> FStar.Pervasives.Lemma (ensures (a + b) % c == (a % c + b % c) % c)
{ "end_col": 3, "end_line": 584, "start_col": 2, "start_line": 578 }
FStar.Pervasives.Lemma
val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1))
val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a: int) (m: pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) =
false
null
true
mod_mul_div_exact a 2 (pow2 (m - 1))
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.mod_mul_div_exact", "Prims.pow2", "Prims.op_Subtraction", "Prims.unit", "Prims.eq2", "Prims.op_Modulus", "Prims.squash", "Prims.op_Division", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0)
[]
FStar.Math.Lemmas.mod_pow2_div2
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> m: Prims.pos -> FStar.Pervasives.Lemma (requires a % Prims.pow2 m == 0) (ensures a / 2 % Prims.pow2 (m - 1) == 0)
{ "end_col": 38, "end_line": 675, "start_col": 2, "start_line": 675 }
FStar.Pervasives.Lemma
val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; ()
val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) let lemma_mod_mult_zero a b c =
false
null
true
lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; ()
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "Prims.unit", "FStar.Math.Lemmas.nat_over_pos_is_nat", "Prims.op_Division", "Prims.op_Modulus", "FStar.Mul.op_Star", "FStar.Math.Lemmas.lemma_div_lt_cancel", "FStar.Math.Lemmas.lemma_mod_lt" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c =
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0)
[]
FStar.Math.Lemmas.lemma_mod_mult_zero
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.pos -> c: Prims.pos -> FStar.Pervasives.Lemma (ensures a % (b * c) / b / c == 0)
{ "end_col": 4, "end_line": 705, "start_col": 2, "start_line": 698 }
FStar.Pervasives.Lemma
val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c)
val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c =
false
null
true
pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c)
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Math.Lemmas.multiple_division_lemma", "Prims.pow2", "Prims.unit", "FStar.Math.Lemmas.division_multiplication_lemma", "FStar.Mul.op_Star", "Prims.op_Subtraction", "FStar.Math.Lemmas.pow2_plus" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c))
[]
FStar.Math.Lemmas.pow2_multiplication_division_lemma_2
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.nat -> c: Prims.nat{c <= b} -> FStar.Pervasives.Lemma (ensures a * Prims.pow2 c / Prims.pow2 b = a / Prims.pow2 (b - c))
{ "end_col": 36, "end_line": 827, "start_col": 2, "start_line": 825 }
FStar.Pervasives.Lemma
val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; }
val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a: int) (n q: pos) =
false
null
true
calc ( == ) { a % n; ( == ) { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; ( == ) { () } ((n * q) * (a / (n * q))) % n; ( == ) { (paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q)))) } ((q * (a / (n * q))) * n) % n; ( == ) { multiple_modulo_lemma (q * (a / (n * q))) n } 0; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.op_Addition", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_mod", "Prims.squash", "FStar.Math.Lemmas.swap_mul", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.multiple_modulo_lemma" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0)
[]
FStar.Math.Lemmas.mod_mult_exact
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> n: Prims.pos -> q: Prims.pos -> FStar.Pervasives.Lemma (requires a % (n * q) == 0) (ensures a % n == 0)
{ "end_col": 3, "end_line": 649, "start_col": 2, "start_line": 638 }
FStar.Pervasives.Lemma
val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 )
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow2_multiplication_modulo_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b)
val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 ) let pow2_multiplication_modulo_lemma_1 a b c =
false
null
true
pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b)
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Math.Lemmas.multiple_modulo_lemma", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Subtraction", "Prims.unit", "FStar.Math.Lemmas.paren_mul_left", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.pow2_plus" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c) val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 )
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 )
[]
FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_1
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.nat -> c: Prims.nat{c >= b} -> FStar.Pervasives.Lemma (ensures a * Prims.pow2 c % Prims.pow2 b = 0)
{ "end_col": 51, "end_line": 835, "start_col": 2, "start_line": 832 }
FStar.Pervasives.Lemma
val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; }
val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) let cancel_fraction a b c =
false
null
true
calc ( == ) { (a * c) / (b * c); ( == ) { swap_mul b c } (a * c) / (c * b); ( == ) { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; ( == ) { cancel_mul_div a c } a / b; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Division", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.swap_mul", "Prims.squash", "FStar.Math.Lemmas.division_multiplication_lemma", "FStar.Math.Lemmas.cancel_mul_div" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b)
[]
FStar.Math.Lemmas.cancel_fraction
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.pos -> c: Prims.pos -> FStar.Pervasives.Lemma (ensures a * c / (b * c) == a / b)
{ "end_col": 3, "end_line": 735, "start_col": 2, "start_line": 727 }
FStar.Pervasives.Lemma
val lemma_mod_plus_injective (n:pos) (a:int) (b:nat) (c:nat) : Lemma (requires b < n /\ c < n /\ (a + b) % n = (a + c) % n) (ensures b = c)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_mod_plus_injective (n:pos) (a:int) (b:nat) (c:nat) = small_mod b n; small_mod c n; mod_add_both (a + b) (a + c) (-a) n
val lemma_mod_plus_injective (n:pos) (a:int) (b:nat) (c:nat) : Lemma (requires b < n /\ c < n /\ (a + b) % n = (a + c) % n) (ensures b = c) let lemma_mod_plus_injective (n: pos) (a: int) (b c: nat) =
false
null
true
small_mod b n; small_mod c n; mod_add_both (a + b) (a + c) (- a) n
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.pos", "Prims.int", "Prims.nat", "FStar.Math.Lemmas.mod_add_both", "Prims.op_Addition", "Prims.op_Minus", "Prims.unit", "FStar.Math.Lemmas.small_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c) val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 ) let pow2_multiplication_modulo_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c ) let pow2_multiplication_modulo_lemma_2 a b c = calc (==) { (a * pow2 c) % pow2 b; == {} (a * pow2 c) % pow2 (c + (b-c)); == { pow2_plus c (b-c) } (a * pow2 c) % (pow2 c * pow2 (b-c)); == { modulo_scale_lemma a (pow2 c) (pow2 (b-c)) } (a % pow2 (b - c)) * pow2 c; } val pow2_modulo_division_lemma_1: a:nat -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) / pow2 b = (a / pow2 b) % (pow2 (c - b)) ) let pow2_modulo_division_lemma_1 a b c = pow2_plus (c - b) b; modulo_division_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) / pow2 b = 0 ) let pow2_modulo_division_lemma_2 a b c = pow2_le_compat b c; small_division_lemma_1 (a % pow2 c) (pow2 b) val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b ) let pow2_modulo_modulo_lemma_1 a b c = pow2_plus (c - b) b; modulo_modulo_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 c ) let pow2_modulo_modulo_lemma_2 a b c = pow2_le_compat b c; small_modulo_lemma_1 (a % pow2 c) (pow2 b) val modulo_add : p:pos -> a:int -> b:int -> c:int -> Lemma (requires (b % p = c % p)) (ensures ((a + b) % p = (a + c) % p)) let modulo_add p a b c = modulo_distributivity a b p; modulo_distributivity a c p val lemma_mod_twice : a:int -> p:pos -> Lemma ((a % p) % p == a % p) let lemma_mod_twice a p = lemma_mod_mod (a % p) a p val modulo_sub : p:pos -> a:int -> b:int -> c:int -> Lemma (requires ((a + b) % p = (a + c) % p)) (ensures (b % p = c % p)) let modulo_sub p a b c = modulo_add p (-a) (a + b) (a + c) val mod_add_both (a:int) (b:int) (x:int) (n:pos) : Lemma (requires a % n == b % n) (ensures (a + x) % n == (b + x) % n) let mod_add_both (a:int) (b:int) (x:int) (n:pos) = calc (==) { (a + x) % n; == { modulo_distributivity a x n } ((a % n) + (x % n)) % n; == { (* hyp *) } ((b % n) + (x % n)) % n; == { modulo_distributivity b x n } (b + x) % n; } val lemma_mod_plus_injective (n:pos) (a:int) (b:nat) (c:nat) : Lemma (requires b < n /\ c < n /\ (a + b) % n = (a + c) % n) (ensures b = c)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_mod_plus_injective (n:pos) (a:int) (b:nat) (c:nat) : Lemma (requires b < n /\ c < n /\ (a + b) % n = (a + c) % n) (ensures b = c)
[]
FStar.Math.Lemmas.lemma_mod_plus_injective
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
n: Prims.pos -> a: Prims.int -> b: Prims.nat -> c: Prims.nat -> FStar.Pervasives.Lemma (requires b < n /\ c < n /\ (a + b) % n = (a + c) % n) (ensures b = c)
{ "end_col": 37, "end_line": 912, "start_col": 2, "start_line": 910 }
FStar.Pervasives.Lemma
val pow2_modulo_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 c )
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let pow2_modulo_modulo_lemma_2 a b c = pow2_le_compat b c; small_modulo_lemma_1 (a % pow2 c) (pow2 b)
val pow2_modulo_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 c ) let pow2_modulo_modulo_lemma_2 a b c =
false
null
true
pow2_le_compat b c; small_modulo_lemma_1 (a % pow2 c) (pow2 b)
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Math.Lemmas.small_modulo_lemma_1", "Prims.op_Modulus", "Prims.pow2", "Prims.unit", "FStar.Math.Lemmas.pow2_le_compat" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c) val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 ) let pow2_multiplication_modulo_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c ) let pow2_multiplication_modulo_lemma_2 a b c = calc (==) { (a * pow2 c) % pow2 b; == {} (a * pow2 c) % pow2 (c + (b-c)); == { pow2_plus c (b-c) } (a * pow2 c) % (pow2 c * pow2 (b-c)); == { modulo_scale_lemma a (pow2 c) (pow2 (b-c)) } (a % pow2 (b - c)) * pow2 c; } val pow2_modulo_division_lemma_1: a:nat -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) / pow2 b = (a / pow2 b) % (pow2 (c - b)) ) let pow2_modulo_division_lemma_1 a b c = pow2_plus (c - b) b; modulo_division_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) / pow2 b = 0 ) let pow2_modulo_division_lemma_2 a b c = pow2_le_compat b c; small_division_lemma_1 (a % pow2 c) (pow2 b) val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b ) let pow2_modulo_modulo_lemma_1 a b c = pow2_plus (c - b) b; modulo_modulo_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 c )
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val pow2_modulo_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 c )
[]
FStar.Math.Lemmas.pow2_modulo_modulo_lemma_2
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.nat -> c: Prims.nat{c <= b} -> FStar.Pervasives.Lemma (ensures a % Prims.pow2 c % Prims.pow2 b = a % Prims.pow2 c)
{ "end_col": 44, "end_line": 873, "start_col": 2, "start_line": 872 }
FStar.Pervasives.Lemma
val modulo_add : p:pos -> a:int -> b:int -> c:int -> Lemma (requires (b % p = c % p)) (ensures ((a + b) % p = (a + c) % p))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modulo_add p a b c = modulo_distributivity a b p; modulo_distributivity a c p
val modulo_add : p:pos -> a:int -> b:int -> c:int -> Lemma (requires (b % p = c % p)) (ensures ((a + b) % p = (a + c) % p)) let modulo_add p a b c =
false
null
true
modulo_distributivity a b p; modulo_distributivity a c p
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.pos", "Prims.int", "FStar.Math.Lemmas.modulo_distributivity", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; } val pow2_multiplication_division_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) / pow2 b = a * pow2 (c - b)) let pow2_multiplication_division_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_division_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) / pow2 b = a / pow2 (b - c)) let pow2_multiplication_division_lemma_2 a b c = pow2_plus c (b - c); division_multiplication_lemma (a * pow2 c) (pow2 c) (pow2 (b - c)); multiple_division_lemma a (pow2 c) val pow2_multiplication_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a * pow2 c) % pow2 b = 0 ) let pow2_multiplication_modulo_lemma_1 a b c = pow2_plus (c - b) b; paren_mul_right a (pow2 (c - b)) (pow2 b); paren_mul_left a (pow2 (c - b)) (pow2 b); multiple_modulo_lemma (a * pow2 (c - b)) (pow2 b) val pow2_multiplication_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a * pow2 c) % pow2 b = (a % pow2 (b - c)) * pow2 c ) let pow2_multiplication_modulo_lemma_2 a b c = calc (==) { (a * pow2 c) % pow2 b; == {} (a * pow2 c) % pow2 (c + (b-c)); == { pow2_plus c (b-c) } (a * pow2 c) % (pow2 c * pow2 (b-c)); == { modulo_scale_lemma a (pow2 c) (pow2 (b-c)) } (a % pow2 (b - c)) * pow2 c; } val pow2_modulo_division_lemma_1: a:nat -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) / pow2 b = (a / pow2 b) % (pow2 (c - b)) ) let pow2_modulo_division_lemma_1 a b c = pow2_plus (c - b) b; modulo_division_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_division_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) / pow2 b = 0 ) let pow2_modulo_division_lemma_2 a b c = pow2_le_compat b c; small_division_lemma_1 (a % pow2 c) (pow2 b) val pow2_modulo_modulo_lemma_1: a:int -> b:nat -> c:nat{c >= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 b ) let pow2_modulo_modulo_lemma_1 a b c = pow2_plus (c - b) b; modulo_modulo_lemma a (pow2 b) (pow2 (c - b)) val pow2_modulo_modulo_lemma_2: a:int -> b:nat -> c:nat{c <= b} -> Lemma ( (a % pow2 c) % pow2 b = a % pow2 c ) let pow2_modulo_modulo_lemma_2 a b c = pow2_le_compat b c; small_modulo_lemma_1 (a % pow2 c) (pow2 b) val modulo_add : p:pos -> a:int -> b:int -> c:int -> Lemma (requires (b % p = c % p)) (ensures ((a + b) % p = (a + c) % p))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modulo_add : p:pos -> a:int -> b:int -> c:int -> Lemma (requires (b % p = c % p)) (ensures ((a + b) % p = (a + c) % p))
[]
FStar.Math.Lemmas.modulo_add
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
p: Prims.pos -> a: Prims.int -> b: Prims.int -> c: Prims.int -> FStar.Pervasives.Lemma (requires b % p = c % p) (ensures (a + b) % p = (a + c) % p)
{ "end_col": 29, "end_line": 880, "start_col": 2, "start_line": 879 }
FStar.Pervasives.Lemma
val modulo_division_lemma_0 (a: nat) (b c: pos) : Lemma (a / (b * c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); ()
val modulo_division_lemma_0 (a: nat) (b c: pos) : Lemma (a / (b * c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) let modulo_division_lemma_0 (a: nat) (b c: pos) : Lemma (a / (b * c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) =
false
null
true
slash_decr_axiom a (b * c); calc ( == ) { (a / (b * c)) * (b * c); ( == ) { swap_mul b c } (a / (b * c)) * (c * b); ( == ) { paren_mul_right (a / (b * c)) c b } ((a / (b * c)) * c) * b; }; cut ((a / (b * c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b * c); division_sub_lemma a b ((a / (b * c)) * c); ()
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.pos", "Prims.unit", "FStar.Math.Lemmas.division_sub_lemma", "FStar.Mul.op_Star", "Prims.op_Division", "FStar.Math.Lemmas.lemma_div_mod", "Prims.cut", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.swap_mul", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lib.slash_decr_axiom", "Prims.l_True", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modulo_division_lemma_0 (a: nat) (b c: pos) : Lemma (a / (b * c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c))
[]
FStar.Math.Lemmas.modulo_division_lemma_0
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.nat -> b: Prims.pos -> c: Prims.pos -> FStar.Pervasives.Lemma (ensures a / (b * c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - (a / (b * c)) * c)
{ "end_col": 6, "end_line": 769, "start_col": 4, "start_line": 758 }
FStar.Pervasives.Lemma
val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; }
val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c =
false
null
true
calc ( == ) { (a * b) % (b * c); ( == ) { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); ( == ) { cancel_fraction a c b } a * b - (b * c) * (a / c); ( == ) { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); ( == ) { (swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b) } (a - c * (a / c)) * b; ( == ) { lemma_div_mod a c } (a % c) * b; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Subtraction", "Prims.op_Division", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_mod", "Prims.squash", "FStar.Math.Lemmas.cancel_fraction", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.distributivity_sub_left", "FStar.Math.Lemmas.swap_mul" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b)
[]
FStar.Math.Lemmas.modulo_scale_lemma
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.pos -> c: Prims.pos -> FStar.Pervasives.Lemma (ensures a * b % (b * c) == (a % c) * b)
{ "end_col": 3, "end_line": 751, "start_col": 2, "start_line": 739 }
FStar.Pervasives.Lemma
val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); }
val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a: int) (b c: pos) =
false
null
true
calc ( == ) { a / b / c; ( == ) { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; ( == ) { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; ( == ) { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; ( == ) { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; ( == ) { lemma_mod_mult_zero a b c } a / (b * c); }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Division", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "Prims.op_Modulus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_mod", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.lemma_div_plus", "FStar.Math.Lemmas.lemma_mod_mult_zero" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c)
[]
FStar.Math.Lemmas.division_multiplication_lemma
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.pos -> c: Prims.pos -> FStar.Pervasives.Lemma (ensures a / (b * c) = a / b / c)
{ "end_col": 3, "end_line": 723, "start_col": 2, "start_line": 711 }
FStar.Pervasives.Lemma
val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; }
val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c =
false
null
true
calc ( == ) { (a % (b * c)) / b; ( == ) { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; ( == ) { (paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c)))) } (a + b * (- (c * (a / (b * c))))) / b; ( == ) { lemma_div_plus a (- (c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); ( == ) { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); ( == ) { lemma_div_mod (a / b) c } (a / b) % c; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.pos", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Division", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Subtraction", "Prims.op_Addition", "Prims.op_Minus", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_mod", "Prims.squash", "FStar.Math.Lemmas.neg_mul_right", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.lemma_div_plus", "FStar.Math.Lemmas.division_multiplication_lemma" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c)
[]
FStar.Math.Lemmas.modulo_division_lemma
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.nat -> b: Prims.pos -> c: Prims.pos -> FStar.Pervasives.Lemma (ensures a % (b * c) / b = a / b % c)
{ "end_col": 3, "end_line": 787, "start_col": 2, "start_line": 775 }
FStar.Pervasives.Lemma
val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d))
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; }
val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d =
false
null
true
calc ( ==> ) { (a <= b) <: Type0; ( ==> ) { (lemma_div_mod a d; lemma_div_mod b d) } d * (a / d) + a % d <= d * (b / d) + b % d; ( ==> ) { () } d * (a / d) - d * (b / d) <= b % d - a % d; ( ==> ) { () } d * (a / d - b / d) <= b % d - a % d; ( ==> ) { () } d * (a / d - b / d) < d; ( ==> ) { () } a / d - b / d <= 0; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.logical", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.op_Division", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_LessThan", "FStar.Mul.op_Star", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Calc.calc_push_impl", "Prims.squash", "FStar.Math.Lemmas.lemma_div_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d))
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d))
[]
FStar.Math.Lemmas.lemma_div_le
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.int -> d: Prims.pos -> FStar.Pervasives.Lemma (requires a <= b) (ensures a / d <= b / d)
{ "end_col": 3, "end_line": 602, "start_col": 2, "start_line": 590 }
FStar.Pervasives.Lemma
val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b)
[ { "abbrev": false, "full_module": "FStar.Math.Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let modulo_modulo_lemma (a:int) (b:pos) (c:pos) = pos_times_pos_is_pos b c; calc (==) { (a % (b * c)) % b; == { calc (==) { a % (b * c); == { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); == { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); }} (a - b * (c * (a / (b * c)))) % b; == { () } (a + (- (b * (c * (a / (b * c)))))) % b; == { neg_mul_right b (c * (a / (b * c))) } (a + (b * (-c * (a / (b * c))))) % b; == { () } (a + (-c * (a / (b * c))) * b) % b; == { lemma_mod_plus a (-c * (a / (b * c))) b} a % b; }
val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b) let modulo_modulo_lemma (a: int) (b c: pos) =
false
null
true
pos_times_pos_is_pos b c; calc ( == ) { (a % (b * c)) % b; ( == ) { calc ( == ) { a % (b * c); ( == ) { lemma_div_mod a (b * c) } a - (b * c) * (a / (b * c)); ( == ) { paren_mul_right b c (a / (b * c)) } a - b * (c * (a / (b * c))); } } (a - b * (c * (a / (b * c)))) % b; ( == ) { () } (a + (- (b * (c * (a / (b * c)))))) % b; ( == ) { neg_mul_right b (c * (a / (b * c))) } (a + (b * (- c * (a / (b * c))))) % b; ( == ) { () } (a + (- c * (a / (b * c))) * b) % b; ( == ) { lemma_mod_plus a (- c * (a / (b * c))) b } a % b; }
{ "checked_file": "FStar.Math.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "FStar.Math.Lemmas.fst" }
[ "lemma" ]
[ "Prims.int", "Prims.pos", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Addition", "Prims.op_Minus", "Prims.op_Division", "Prims.op_Subtraction", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_mod", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.neg_mul_right", "FStar.Math.Lemmas.lemma_mod_plus", "FStar.Math.Lemmas.pos_times_pos_is_pos" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Math.Lemmas open FStar.Mul open FStar.Math.Lib #push-options "--fuel 0 --ifuel 0" (* Lemma: definition of Euclidean division *) val euclidean_div_axiom: a:int -> b:pos -> Lemma (a - b * (a / b) >= 0 /\ a - b * (a / b) < b) let euclidean_div_axiom a b = () val lemma_eucl_div_bound: a:int -> b:int -> q:int -> Lemma (requires (a < q)) (ensures (a + q * b < q * (b+1))) let lemma_eucl_div_bound a b q = () val lemma_mult_le_left: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (a * b <= a * c)) let lemma_mult_le_left a b c = () val lemma_mult_le_right: a:nat -> b:int -> c:int -> Lemma (requires (b <= c)) (ensures (b * a <= c * a)) let lemma_mult_le_right a b c = () val lemma_mult_lt_left: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (a * b < a * c)) let lemma_mult_lt_left a b c = () val lemma_mult_lt_right: a:pos -> b:int -> c:int -> Lemma (requires (b < c)) (ensures (b * a < c * a)) let lemma_mult_lt_right a b c = () let lemma_mult_lt_sqr (n:nat) (m:nat) (k:nat{n < k && m < k}) : Lemma (n * m < k * k) = calc (<=) { n * m; <= { lemma_mult_le_left n m (k - 1) } n * (k - 1); <= { lemma_mult_le_right (k - 1) n (k - 1) } (k - 1) * (k - 1); <= {} k*k - 1; } (* Lemma: multiplication on integers is commutative *) val swap_mul: a:int -> b:int -> Lemma (a * b = b * a) let swap_mul a b = () val lemma_cancel_mul (a b : int) (n : pos) : Lemma (requires (a * n = b * n)) (ensures (a = b)) let lemma_cancel_mul a b n = () (* Lemma: multiplication is right distributive over addition *) val distributivity_add_left: a:int -> b:int -> c:int -> Lemma ((a + b) * c = a * c + b * c) let distributivity_add_left a b c = () (* Lemma: multiplication is left distributive over addition *) val distributivity_add_right: a:int -> b:int -> c:int -> Lemma (a * (b + c) = a * b + a * c) let distributivity_add_right a b c = calc (==) { a * (b + c); == {} (b + c) * a; == { distributivity_add_left b c a } b * a + c * a; == {} a * b + a * c; } (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) (* GM: This is really just an identity since the LHS is associated to the left *) val paren_mul_left: a:int -> b:int -> c:int -> Lemma (a * b * c = (a * b) * c) let paren_mul_left a b c = () (* Lemma: multiplication is associative, hence parenthesizing is meaningless *) val paren_mul_right: a:int -> b:int -> c:int -> Lemma (a * b * c = a * (b * c)) let paren_mul_right a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_left: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c) let paren_add_left a b c = () (* Lemma: addition is associative, hence parenthesizing is meaningless *) val paren_add_right: a:int -> b:int -> c:int -> Lemma (a + b + c = a + (b + c)) let paren_add_right a b c = () val addition_is_associative: a:int -> b:int -> c:int -> Lemma (a + b + c = (a + b) + c /\ a + b + c = a + (b + c)) let addition_is_associative a b c = () val subtraction_is_distributive: a:int -> b:int -> c:int -> Lemma (a - b + c = (a - b) + c /\ a - b - c = a - (b + c) /\ a - b - c = (a - b) - c /\ a + (-b - c) = a - b - c /\ a - (b - c) = a - b + c) let subtraction_is_distributive a b c = () val swap_add_plus_minus: a:int -> b:int -> c:int -> Lemma (a + b - c = (a - c) + b) let swap_add_plus_minus a b c = () (* Lemma: minus applies to the whole term *) val neg_mul_left: a:int -> b:int -> Lemma (-(a * b) = (-a) * b) let neg_mul_left a b = () (* Lemma: minus applies to the whole term *) val neg_mul_right: a:int -> b:int -> Lemma (-(a * b) = a * (-b)) let neg_mul_right a b = () val swap_neg_mul: a:int -> b:int -> Lemma ((-a) * b = a * (-b)) let swap_neg_mul a b = neg_mul_left a b; neg_mul_right a b (* Lemma: multiplication is left distributive over subtraction *) val distributivity_sub_left: a:int -> b:int -> c:int -> Lemma ((a - b) * c = a * c - b * c) let distributivity_sub_left a b c = calc (==) { (a - b) * c; == {} (a + (-b)) * c; == { distributivity_add_left a (-b) c } a * c + (-b) * c; == { neg_mul_left b c } a * c - b * c; } (* Lemma: multiplication is right distributive over subtraction *) val distributivity_sub_right: a:int -> b:int -> c:int -> Lemma ((a * (b - c) = a * b - a * c)) let distributivity_sub_right a b c = calc (==) { a * (b - c); == {} a * (b + (-c)); == { distributivity_add_right a b (-c) } a * b + a * (-c); == { neg_mul_right a c } a * b - a * c; } (* Lemma: multiplication precedence on addition *) val mul_binds_tighter: a:int -> b:int -> c:int -> Lemma (a + (b * c) = a + b * c) let mul_binds_tighter a b c = () val lemma_abs_mul : a:int -> b:int -> Lemma (abs a * abs b = abs (a * b)) let lemma_abs_mul a b = () val lemma_abs_bound : a:int -> b:nat -> Lemma (abs a < b <==> -b < a /\ a < b) let lemma_abs_bound a b = () (* Lemma: multiplication keeps symmetric bounds : b > 0 && d > 0 && -b < a < b && -d < c < d ==> - b * d < a * c < b * d *) val mul_ineq1: a:int -> b:nat -> c:int -> d:nat -> Lemma (requires (-b < a /\ a < b /\ -d < c /\ c < d)) (ensures (-(b * d) < a * c /\ a * c < b * d)) let mul_ineq1 a b c d = if a = 0 || c = 0 then () else begin lemma_abs_bound a b; lemma_abs_bound c d; lemma_abs_mul a c; lemma_mult_lt_left (abs a) (abs c) d; lemma_mult_lt_right d (abs a) b; lemma_abs_bound (a * c) (b * d); () end (* Zero is neutral for addition *) let add_zero_left_is_same (n : int) : Lemma(0 + n = n) = () let add_zero_right_is_same (n : int) : Lemma(n + 0 = n) = () (* One is neutral for multiplication *) let mul_one_left_is_same (n : int) : Lemma(1 * n = n) = () let mul_one_right_is_same (n : int) : Lemma(n * 1 = n) = () (* Multiplying by zero gives zero *) let mul_zero_left_is_zero (n : int) : Lemma(0 * n = 0) = () let mul_zero_right_is_zero (n : int) : Lemma(n * 0 = 0) = () val nat_times_nat_is_nat: a:nat -> b:nat -> Lemma (a * b >= 0) let nat_times_nat_is_nat a b = () val pos_times_pos_is_pos: a:pos -> b:pos -> Lemma (a * b > 0) let pos_times_pos_is_pos a b = () val nat_over_pos_is_nat: a:nat -> b:pos -> Lemma (a / b >= 0) let nat_over_pos_is_nat a b = () val nat_plus_nat_equal_zero_lemma: a:nat -> b:nat{a + b = 0} -> Lemma(a = 0 /\ b = 0) let nat_plus_nat_equal_zero_lemma a b = () val int_times_int_equal_zero_lemma: a:int -> b:int{a * b = 0} -> Lemma(a = 0 \/ b = 0) let int_times_int_equal_zero_lemma a b = () #push-options "--fuel 1" val pow2_double_sum: n:nat -> Lemma (pow2 n + pow2 n = pow2 (n + 1)) let pow2_double_sum n = () val pow2_double_mult: n:nat -> Lemma (2 * pow2 n = pow2 (n + 1)) let pow2_double_mult n = pow2_double_sum n val pow2_lt_compat: n:nat -> m:nat -> Lemma (requires (m < n)) (ensures (pow2 m < pow2 n)) (decreases m) let rec pow2_lt_compat n m = match m with | 0 -> () | _ -> pow2_lt_compat (n-1) (m-1) #pop-options val pow2_le_compat: n:nat -> m:nat -> Lemma (requires (m <= n)) (ensures (pow2 m <= pow2 n)) let pow2_le_compat n m = if m < n then pow2_lt_compat n m #push-options "--fuel 1" val pow2_plus: n:nat -> m:nat -> Lemma (ensures (pow2 n * pow2 m = pow2 (n + m))) (decreases n) let rec pow2_plus n m = match n with | 0 -> () | _ -> pow2_plus (n - 1) m #pop-options (* Lemma : definition of the exponential property of pow2 *) val pow2_minus: n:nat -> m:nat{ n >= m } -> Lemma ((pow2 n) / (pow2 m) = pow2 (n - m)) let pow2_minus n m = pow2_plus (n - m) m; slash_star_axiom (pow2 (n - m)) (pow2 m) (pow2 n) (* Lemma: loss of precision in euclidean division *) val multiply_fractions (a:int) (n:nonzero) : Lemma (n * ( a / n ) <= a) let multiply_fractions a n = () (** Same as `small_mod` *) val modulo_lemma: a:nat -> b:pos -> Lemma (requires (a < b)) (ensures (a % b = a)) let modulo_lemma a b = () (** Same as `lemma_div_def` in Math.Lib *) val lemma_div_mod: a:int -> p:nonzero -> Lemma (a = p * (a / p) + a % p) let lemma_div_mod a p = () val lemma_mod_lt: a:int -> p:pos -> Lemma (0 <= a % p /\ a % p < p /\ (a >= 0 ==> a % p <= a)) let lemma_mod_lt a p = () val lemma_div_lt_nat: a:int -> n:nat -> m:nat{m <= n} -> Lemma (requires (a < pow2 n)) (ensures (a / pow2 m < pow2 (n-m))) let lemma_div_lt_nat a n m = lemma_div_mod a (pow2 m); assert(a = pow2 m * (a / pow2 m) + a % pow2 m); pow2_plus m (n-m); assert(pow2 n = pow2 m * pow2 (n - m)) val lemma_div_lt (a:int) (n:nat) (m:nat) : Lemma (requires m <= n /\ a < pow2 n) (ensures a / pow2 m < pow2 (n-m)) let lemma_div_lt a n m = if a >= 0 then lemma_div_lt_nat a n m val bounded_multiple_is_zero (x:int) (n:pos) : Lemma (requires -n < x * n /\ x * n < n) (ensures x == 0) let bounded_multiple_is_zero (x:int) (n:pos) = () val small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) let small_div (a:nat) (n:pos) : Lemma (requires a < n) (ensures a / n == 0) = () val small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) let small_mod (a:nat) (n:pos) : Lemma (requires a < n) (ensures a % n == a) = () val lt_multiple_is_equal (a:nat) (b:nat) (x:int) (n:nonzero) : Lemma (requires a < n /\ b < n /\ a == b + x * n) (ensures a == b /\ x == 0) let lt_multiple_is_equal a b x n = assert (0 * n == 0); bounded_multiple_is_zero x n val lemma_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) % n = a % n) let lemma_mod_plus (a:int) (k:int) (n:pos) = calc (==) { (a+k*n)%n - a%n; == { lemma_div_mod a n; lemma_div_mod (a+k*n) n } ((a + k*n) - n*((a + k*n)/n)) - (a - n*(a/n)); == {} n*k + n*(a/n) - n*((a + k*n)/n); == { distributivity_add_right n k (a/n); distributivity_sub_right n (k + a/n) ((a + k*n)/n) } n * (k + a/n - (a+k*n)/n); }; lt_multiple_is_equal ((a+k*n)%n) (a%n) (k + a/n - (a+k*n)/n) n; () val lemma_div_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k) let lemma_div_plus (a:int) (k:int) (n:pos) = calc (==) { n * ((a+k*n)/n - a/n); == { distributivity_sub_right n ((a+k*n)/n) (a/n) } n * ((a+k*n)/n) - n*(a/n); == { lemma_div_mod (a+k*n) n; lemma_div_mod a n } (a + k*n - (a+k*n)%n) - (a - a%n); == {} k*n - (a+k*n)%n + a%n; == { lemma_mod_plus a k n } k*n; }; lemma_cancel_mul ((a+k*n)/n - a/n) k n let lemma_div_mod_plus (a:int) (k:int) (n:pos) : Lemma ((a + k * n) / n = a / n + k /\ (a + k * n) % n = a % n) = lemma_div_plus a k n; lemma_mod_plus a k n val add_div_mod_1 (a:int) (n:pos) : Lemma ((a + n) % n == a % n /\ (a + n) / n == a / n + 1) let add_div_mod_1 a n = lemma_mod_plus a 1 n; lemma_div_plus a 1 n val sub_div_mod_1 (a:int) (n:pos) : Lemma ((a - n) % n == a % n /\ (a - n) / n == a / n - 1) let sub_div_mod_1 a n = lemma_mod_plus a (-1) n; lemma_div_plus a (-1) n #push-options "--smtencoding.elim_box true --smtencoding.nl_arith_repr native" val cancel_mul_div (a:int) (n:nonzero) : Lemma ((a * n) / n == a) let cancel_mul_div (a:int) (n:nonzero) = () #pop-options val cancel_mul_mod (a:int) (n:pos) : Lemma ((a * n) % n == 0) let cancel_mul_mod (a:int) (n:pos) = small_mod 0 n; lemma_mod_plus 0 a n val lemma_mod_add_distr (a:int) (b:int) (n:pos) : Lemma ((a + b % n) % n = (a + b) % n) let lemma_mod_add_distr (a:int) (b:int) (n:pos) = calc (==) { (a + b%n) % n; == { lemma_mod_plus (a + (b % n)) (b / n) n } (a + b%n + n * (b/n)) % n; == { lemma_div_mod b n } (a + b) % n; } val lemma_mod_sub_distr (a:int) (b:int) (n:pos) : Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr (a:int) (b:int) (n:pos) = calc (==) { (a - b%n) % n; == { lemma_mod_plus (a - (b % n)) (-(b / n)) n } (a - b%n + n * (-(b/n))) % n; == { neg_mul_right n (b/n) } (a - b%n - n * (b/n)) % n; == { lemma_div_mod b n } (a - b) % n; } val lemma_mod_sub_0: a:pos -> Lemma ((-1) % a = a - 1) let lemma_mod_sub_0 a = () val lemma_mod_sub_1: a:pos -> b:pos{a < b} -> Lemma ((-a) % b = b - (a%b)) let lemma_mod_sub_1 a b = calc (==) { (-a) % b; == { lemma_mod_plus (-a) 1 b } ((-a) + 1*b) % b; == {} (b - a) % b; == { small_mod (b-a) b } b - a; == { small_mod a b } b - a%b; } val lemma_mod_mul_distr_l (a:int) (b:int) (n:pos) : Lemma (requires True) (ensures (a * b) % n = ((a % n) * b) % n) let lemma_mod_mul_distr_l a b n = calc (==) { (a * b) % n; == { lemma_div_mod a n } ((n * (a/n) + a%n) * b) % n; == { distributivity_add_left (n * (a/n)) (a%n) b } (n * (a/n) * b + (a%n) * b) % n; == { paren_mul_right n (a/n) b; swap_mul ((a/n) * b) n } ((a%n) * b + ((a/n) * b) * n) % n; == { lemma_mod_plus ((a%n) * b) ((a/n) * b) n } ((a%n) * b) % n; } val lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) : Lemma ((a * b) % n = (a * (b % n)) % n) let lemma_mod_mul_distr_r (a:int) (b:int) (n:pos) = calc (==) { (a * b) % n; == { swap_mul a b } (b * a) % n; == { lemma_mod_mul_distr_l b a n } (b%n * a) % n; == { swap_mul a (b%n) } (a * (b%n)) % n; } val lemma_mod_injective: p:pos -> a:nat -> b:nat -> Lemma (requires (a < p /\ b < p /\ a % p = b % p)) (ensures (a = b)) let lemma_mod_injective p a b = () val lemma_mul_sub_distr: a:int -> b:int -> c:int -> Lemma (a * b - a * c = a * (b - c)) let lemma_mul_sub_distr a b c = distributivity_sub_right a b c val lemma_div_exact: a:int -> p:pos -> Lemma (requires (a % p = 0)) (ensures (a = p * (a / p))) let lemma_div_exact a p = () val div_exact_r (a:int) (n:pos) : Lemma (requires (a % n = 0)) (ensures (a = (a / n) * n)) let div_exact_r (a:int) (n:pos) = lemma_div_exact a n val lemma_mod_spec: a:int -> p:pos -> Lemma (a / p = (a - (a % p)) / p) let lemma_mod_spec a p = calc (==) { (a - a%p)/p; == { lemma_div_mod a p } (p*(a/p))/p; == { cancel_mul_div (a/p) p } a/p; } val lemma_mod_spec2: a:int -> p:pos -> Lemma (let q:int = (a - (a % p)) / p in a = (a % p) + q * p) let lemma_mod_spec2 a p = calc (==) { (a % p) + ((a - (a % p)) / p) * p; == { lemma_mod_spec a p } (a % p) + (a / p) * p; == { lemma_div_mod a p } a; } val lemma_mod_plus_distr_l: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = ((a % p) + b) % p) let lemma_mod_plus_distr_l a b p = let q = (a - (a % p)) / p in lemma_mod_spec2 a p; lemma_mod_plus (a % p + b) q p val lemma_mod_plus_distr_r: a:int -> b:int -> p:pos -> Lemma ((a + b) % p = (a + (b % p)) % p) let lemma_mod_plus_distr_r a b p = lemma_mod_plus_distr_l b a p val lemma_mod_mod: a:int -> b:int -> p:pos -> Lemma (requires (a = b % p)) (ensures (a % p = b % p)) let lemma_mod_mod a b p = lemma_mod_lt b p; modulo_lemma (b % p) p (* * Lemmas about multiplication, division and modulo. **) (* * This part focuses on the situation where **) (* * dividend: nat divisor: pos **) (* * TODO: add triggers for certain lemmas. **) (* Lemma: Definition of euclidean division *) val euclidean_division_definition: a:int -> b:nonzero -> Lemma (a = (a / b) * b + a % b) let euclidean_division_definition a b = () (* Lemma: Propriety about modulo *) val modulo_range_lemma: a:int -> b:pos -> Lemma (a % b >= 0 && a % b < b) let modulo_range_lemma a b = () val small_modulo_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a % b = a) let small_modulo_lemma_1 a b = () val small_modulo_lemma_2: a:int -> b:pos -> Lemma (requires a % b = a) (ensures a < b) let small_modulo_lemma_2 a b = () val small_division_lemma_1: a:nat -> b:nonzero -> Lemma (requires a < b) (ensures a / b = 0) let small_division_lemma_1 a b = () val small_division_lemma_2 (a:int) (n:pos) : Lemma (requires a / n = 0) (ensures 0 <= a /\ a < n) let small_division_lemma_2 (a:int) (n:pos) = lemma_div_mod a n (* Lemma: Multiplication by a positive integer preserves order *) val multiplication_order_lemma: a:int -> b:int -> p:pos -> Lemma (a >= b <==> a * p >= b * p) let multiplication_order_lemma a b p = () (* Lemma: Propriety about multiplication after division *) val division_propriety: a:int -> b:pos -> Lemma (a - b < (a / b) * b && (a / b) * b <= a) let division_propriety a b = () (* Internal lemmas for proving the definition of division *) val division_definition_lemma_1: a:int -> b:pos -> m:int{a - b < m * b} -> Lemma (m > a / b - 1) let division_definition_lemma_1 a b m = if a / b - 1 < 0 then () else begin division_propriety a b; multiplication_order_lemma m (a / b - 1) b end val division_definition_lemma_2: a:int -> b:pos -> m:int{m * b <= a} -> Lemma (m < a / b + 1) let division_definition_lemma_2 a b m = division_propriety a b; multiplication_order_lemma (a / b + 1) m b (* Lemma: Definition of division *) val division_definition: a:int -> b:pos -> m:int{a - b < m * b && m * b <= a} -> Lemma (m = a / b) let division_definition a b m = division_definition_lemma_1 a b m; division_definition_lemma_2 a b m (* Lemma: (a * b) / b = a; identical to `cancel_mul_div` above *) val multiple_division_lemma (a:int) (n:nonzero) : Lemma ((a * n) / n = a) let multiple_division_lemma (a:int) (n:nonzero) = cancel_mul_div a n (* Lemma: (a * b) % b = 0 *) val multiple_modulo_lemma (a:int) (n:pos) : Lemma ((a * n) % n = 0) let multiple_modulo_lemma (a:int) (n:pos) = cancel_mul_mod a n (* Lemma: Division distributivity under special condition *) val division_addition_lemma: a:int -> b:pos -> n:int -> Lemma ( (a + n * b) / b = a / b + n ) let division_addition_lemma a b n = division_definition (a + n * b) b (a / b + n) (* Lemma: Modulo distributivity *) val modulo_distributivity: a:int -> b:int -> c:pos -> Lemma ((a + b) % c == (a % c + b % c) % c) let modulo_distributivity a b c = calc (==) { (a + b) % c; == { lemma_mod_plus_distr_l a b c } ((a % c) + b) % c; == { lemma_mod_plus_distr_r (a % c) b c } ((a % c) + (b % c)) % c; } val lemma_div_le: a:int -> b:int -> d:pos -> Lemma (requires (a <= b)) (ensures (a / d <= b / d)) let lemma_div_le a b d = calc (==>) { (a <= b) <: Type0; ==> { lemma_div_mod a d; lemma_div_mod b d } d * (a/d) + a%d <= d * (b/d) + b%d; ==> {} d * (a/d) - d * (b/d) <= b%d - a%d; ==> {} d * (a/d - b/d) <= b%d - a%d; ==> { (* a%d >= 0, and b%d < d*) } d * (a/d - b/d) < d; ==> {} a/d - b/d <= 0; } (* Lemma: Division distributivity under special condition *) val division_sub_lemma (a:int) (n:pos) (b:nat) : Lemma ((a - b * n) / n = a / n - b) let division_sub_lemma (a:int) (n:pos) (b:nat) = neg_mul_left b n; lemma_div_plus a (-b) n val lemma_mod_plus_mul_distr: a:int -> b:int -> c:int -> p:pos -> Lemma (((a + b) * c) % p = ((((a % p) + (b % p)) % p) * (c % p)) % p) let lemma_mod_plus_mul_distr a b c p = calc (==) { ((a + b) * c) % p; == { lemma_mod_mul_distr_l (a + b) c p } (((a + b) % p) * c) % p; == { lemma_mod_mul_distr_r ((a + b) % p) c p } (((a + b) % p) * (c % p)) % p; == { modulo_distributivity a b p } ((((a % p) + (b % p)) % p) * (c % p)) % p; } (* Lemma: Modulo distributivity under special condition *) val modulo_addition_lemma (a:int) (n:pos) (b:int) : Lemma ((a + b * n) % n = a % n) let modulo_addition_lemma (a:int) (n:pos) (b:int) = lemma_mod_plus a b n (* Lemma: Modulo distributivity under special condition *) val lemma_mod_sub (a:int) (n:pos) (b:int) : Lemma (ensures (a - b * n) % n = a % n) let lemma_mod_sub (a:int) (n:pos) (b:int) = neg_mul_left b n; lemma_mod_plus a (-b) n val mod_mult_exact (a:int) (n:pos) (q:pos) : Lemma (requires (a % (n * q) == 0)) (ensures a % n == 0) let mod_mult_exact (a:int) (n:pos) (q:pos) = calc (==) { a % n; == { lemma_div_mod a (n * q) } ((n * q) * (a / (n * q)) + a % (n * q)) % n; == { (* hyp *) } ((n * q) * (a / (n * q))) % n; == { paren_mul_right n q (a / (n * q)); swap_mul n (q * (a / (n * q))) } ((q * (a / (n * q))) * n) % n; == { multiple_modulo_lemma (q * (a / (n*q))) n } 0; } val mod_mul_div_exact (a:int) (b:pos) (n:pos) : Lemma (requires (a % (b * n) == 0)) (ensures (a / b) % n == 0) let mod_mul_div_exact (a:int) (b:pos) (n:pos) = calc (==) { (a / b) % n; == { lemma_div_mod a (b * n) (* + hyp *) } (((b*n)*(a / (b*n))) / b) % n; == { paren_mul_right b n (a / (b*n)) } ((b*(n*(a / (b*n)))) / b) % n; == { cancel_mul_div (n * (a / (b * n))) b } (n*(a / (b*n))) % n; == { cancel_mul_mod (a / (b*n)) n } 0; } #push-options "--fuel 1" val mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) let mod_pow2_div2 (a:int) (m:pos) : Lemma (requires a % pow2 m == 0) (ensures (a / 2) % pow2 (m - 1) == 0) = mod_mul_div_exact a 2 (pow2 (m - 1)) #pop-options private val lemma_div_lt_cancel (a : int) (b : pos) (n : int) : Lemma (requires (a < b * n)) (ensures (a / b < n)) private let lemma_div_lt_cancel a b n = (* by contradiction *) if a / b >= n then begin calc (>=) { a; >= { slash_decr_axiom a b } (a / b) * b; >= {} n * b; }; assert False end private val lemma_mod_mult_zero (a : int) (b : pos) (c : pos) : Lemma ((a % (b * c)) / b / c == 0) private let lemma_mod_mult_zero a b c = (* < 1 *) lemma_mod_lt a (b * c); lemma_div_lt_cancel (a % (b * c)) b c; lemma_div_lt_cancel ((a % (b * c)) / b) c 1; (* >= 0 *) nat_over_pos_is_nat (a % (b * c)) b; nat_over_pos_is_nat ((a % (b * c)) / b) c; () (* Lemma: Divided by a product is equivalent to being divided one by one *) val division_multiplication_lemma (a:int) (b:pos) (c:pos) : Lemma (a / (b * c) = (a / b) / c) let division_multiplication_lemma (a:int) (b:pos) (c:pos) = calc (==) { a / b / c; == { lemma_div_mod a (b * c) } ((b * c) * (a / (b * c)) + a % (b * c)) / b / c; == { paren_mul_right b c (a / (b * c)) } (b * (c * (a / (b * c))) + a % (b * c)) / b / c; == { lemma_div_plus (a % (b * c)) (c * (a / (b * c))) b } (c * (a / (b * c)) + ((a % (b * c)) / b)) / c; == { lemma_div_plus ((a % (b * c)) / b) (a / (b * c)) c } (a / (b * c)) + (a % (b * c)) / b / c; == { lemma_mod_mult_zero a b c } a / (b * c); } private val cancel_fraction (a:int) (b:pos) (c:pos) : Lemma ((a * c) / (b * c) == a / b) private let cancel_fraction a b c = calc (==) { (a * c) / (b * c); == { swap_mul b c } (a * c) / (c * b); == { division_multiplication_lemma (a * c) c b } ((a * c) / c) / b; == { cancel_mul_div a c } a / b; } val modulo_scale_lemma : a:int -> b:pos -> c:pos -> Lemma ((a * b) % (b * c) == (a % c) * b) let modulo_scale_lemma a b c = calc (==) { (a * b) % (b * c); == { lemma_div_mod (a * b) (b * c) } a * b - (b * c) * ((a * b) / (b * c)); == { cancel_fraction a c b } a * b - (b * c) * (a / c); == { paren_mul_right b c (a / c) } a * b - b * (c * (a / c)); == { swap_mul b (c * (a / c)); distributivity_sub_left a (c * (a / c)) b } (a - c * (a / c)) * b; == { lemma_div_mod a c } (a % c) * b; } let lemma_mul_pos_pos_is_pos (x:pos) (y:pos) : Lemma (x*y > 0) = () let lemma_mul_nat_pos_is_nat (x:nat) (y:pos) : Lemma (x*y >= 0) = () let modulo_division_lemma_0 (a:nat) (b:pos) (c:pos) : Lemma (a / (b*c) <= a /\ (a - (a / (b * c)) * (b * c)) / b = a / b - ((a / (b * c)) * c)) = slash_decr_axiom a (b*c); calc (==) { (a / (b*c)) * (b * c); == { swap_mul b c } (a / (b*c)) * (c * b); == { paren_mul_right (a / (b*c)) c b } ((a / (b*c)) * c) * b; }; cut ((a / (b*c)) * (b * c) = ((a / (b * c)) * c) * b); lemma_div_mod a (b*c); division_sub_lemma a b ((a / (b*c)) * c); () val modulo_division_lemma: a:nat -> b:pos -> c:pos -> Lemma ((a % (b * c)) / b = (a / b) % c) let modulo_division_lemma a b c = calc (==) { (a % (b * c)) / b; == { lemma_div_mod a (b * c) } (a - (b * c) * (a / (b * c))) / b; == { paren_mul_right b c ((a / (b * c))); neg_mul_right b (c * (a / (b * c))) } (a + b * (-(c * (a / (b * c))))) / b; == { lemma_div_plus a (-(c * (a / (b * c)))) b } (a / b) - c * (a / (b * c)); == { division_multiplication_lemma a b c } (a / b) - c * ((a / b) / c); == { lemma_div_mod (a/b) c } (a / b) % c; } val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b)
false
false
FStar.Math.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val modulo_modulo_lemma (a:int) (b:pos) (c:pos) : Lemma ((a % (b * c)) % b = a % b)
[]
FStar.Math.Lemmas.modulo_modulo_lemma
{ "file_name": "ulib/FStar.Math.Lemmas.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: Prims.int -> b: Prims.pos -> c: Prims.pos -> FStar.Pervasives.Lemma (ensures a % (b * c) % b = a % b)
{ "end_col": 3, "end_line": 812, "start_col": 2, "start_line": 793 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let codes = va_codes
let codes =
false
null
false
va_codes
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_codes" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val codes : Type0
[]
Vale.X64.QuickCodes.codes
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 27, "end_line": 15, "start_col": 19, "start_line": 15 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let eval = eval_code
let eval =
false
null
false
eval_code
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.eval_code" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eval : c: Vale.X64.Decls.va_code -> s0: Vale.X64.Decls.va_state -> f0: Vale.X64.Decls.va_fuel -> sN: Vale.X64.Decls.va_state -> Vale.Def.Prop_s.prop0
[]
Vale.X64.QuickCodes.eval
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c: Vale.X64.Decls.va_code -> s0: Vale.X64.Decls.va_state -> f0: Vale.X64.Decls.va_fuel -> sN: Vale.X64.Decls.va_state -> Vale.Def.Prop_s.prop0
{ "end_col": 27, "end_line": 17, "start_col": 18, "start_line": 17 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let code = va_code
let code =
false
null
false
va_code
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_code" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val code : Type0
[]
Vale.X64.QuickCodes.code
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 25, "end_line": 14, "start_col": 18, "start_line": 14 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fuel = va_fuel
let fuel =
false
null
false
va_fuel
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_fuel" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fuel : Type0
[]
Vale.X64.QuickCodes.fuel
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 25, "end_line": 16, "start_col": 18, "start_line": 16 }
Prims.Tot
val if_code (b: bool) (c1 c2: code) : code
[ { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2
val if_code (b: bool) (c1 c2: code) : code let if_code (b: bool) (c1 c2: code) : code =
false
null
false
if b then c1 else c2
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Prims.bool", "Vale.X64.QuickCodes.code" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val if_code (b: bool) (c1 c2: code) : code
[]
Vale.X64.QuickCodes.if_code
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Prims.bool -> c1: Vale.X64.QuickCodes.code -> c2: Vale.X64.QuickCodes.code -> Vale.X64.QuickCodes.code
{ "end_col": 70, "end_line": 50, "start_col": 50, "start_line": 50 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_range1 = mk_range "" 0 0 0 0
let va_range1 =
false
null
false
mk_range "" 0 0 0 0
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "FStar.Range.mk_range" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_range1 : FStar.Range.range
[]
Vale.X64.QuickCodes.va_range1
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.Range.range
{ "end_col": 35, "end_line": 104, "start_col": 16, "start_line": 104 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_Seq_t (a:Type0) = va_state -> a -> Type0
let wp_Seq_t (a: Type0) =
false
null
false
va_state -> a -> Type0
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_state" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_Seq_t : a: Type0 -> Type
[]
Vale.X64.QuickCodes.wp_Seq_t
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Type0 -> Type
{ "end_col": 47, "end_line": 99, "start_col": 25, "start_line": 99 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_Bind_t (a:Type0) = va_state -> a -> Type0
let wp_Bind_t (a: Type0) =
false
null
false
va_state -> a -> Type0
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_state" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_Bind_t : a: Type0 -> Type
[]
Vale.X64.QuickCodes.wp_Bind_t
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Type0 -> Type
{ "end_col": 48, "end_line": 100, "start_col": 26, "start_line": 100 }
Prims.Tot
val va_QBind (#a: Type0) (#b: Type) (#c: code) (#cs: codes) (r: range) (msg: string) (qc: quickCode b c) (qcs: (va_state -> b -> GTot (quickCodes a cs))) : quickCodes a (c :: cs)
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs
val va_QBind (#a: Type0) (#b: Type) (#c: code) (#cs: codes) (r: range) (msg: string) (qc: quickCode b c) (qcs: (va_state -> b -> GTot (quickCodes a cs))) : quickCodes a (c :: cs) let va_QBind (#a: Type0) (#b: Type) (#c: code) (#cs: codes) (r: range) (msg: string) (qc: quickCode b c) (qcs: (va_state -> b -> GTot (quickCodes a cs))) : quickCodes a (c :: cs) =
false
null
false
QBind r msg qc qcs
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCodes.codes", "FStar.Range.range", "Prims.string", "Vale.X64.QuickCode.quickCode", "Vale.X64.Decls.va_state", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCodes.QBind", "Prims.Cons", "Vale.X64.Decls.va_code" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_QBind (#a: Type0) (#b: Type) (#c: code) (#cs: codes) (r: range) (msg: string) (qc: quickCode b c) (qcs: (va_state -> b -> GTot (quickCodes a cs))) : quickCodes a (c :: cs)
[]
Vale.X64.QuickCodes.va_QBind
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> qc: Vale.X64.QuickCode.quickCode b c -> qcs: (_: Vale.X64.Decls.va_state -> _: b -> Prims.GTot (Vale.X64.QuickCodes.quickCodes a cs)) -> Vale.X64.QuickCodes.quickCodes a (c :: cs)
{ "end_col": 206, "end_line": 72, "start_col": 188, "start_line": 72 }
Prims.GTot
val labeled_wrap (r: range) (msg: string) (p: Type0) : GTot Type0
[ { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p
val labeled_wrap (r: range) (msg: string) (p: Type0) : GTot Type0 let labeled_wrap (r: range) (msg: string) (p: Type0) : GTot Type0 =
false
null
false
labeled r msg p
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "sometrivial" ]
[ "FStar.Range.range", "Prims.string", "FStar.Range.labeled" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val labeled_wrap (r: range) (msg: string) (p: Type0) : GTot Type0
[]
Vale.X64.QuickCodes.labeled_wrap
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> p: Type0 -> Prims.GTot Type0
{ "end_col": 80, "end_line": 20, "start_col": 65, "start_line": 20 }
Prims.Tot
val wp_proc (#a: Type0) (c: code) (qc: quickCode a c) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k
val wp_proc (#a: Type0) (c: code) (qc: quickCode a c) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 let wp_proc (#a: Type0) (c: code) (qc: quickCode a c) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 =
false
null
false
match qc with | QProc _ _ wp _ -> wp s0 k
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCode.quickCode", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_code", "Vale.X64.QuickCode.mods_t", "Vale.X64.QuickCode.quickProc_wp", "Vale.X64.QuickCode.t_proof" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_proc (#a: Type0) (c: code) (qc: quickCode a c) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[]
Vale.X64.QuickCodes.wp_proc
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c: Vale.X64.QuickCodes.code -> qc: Vale.X64.QuickCode.quickCode a c -> s0: Vale.X64.Decls.va_state -> k: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> Type0
{ "end_col": 29, "end_line": 97, "start_col": 2, "start_line": 96 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let block = va_Block
let block =
false
null
false
va_Block
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_Block" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val block : block: Vale.X64.Decls.va_codes -> Vale.X64.Decls.va_code
[]
Vale.X64.QuickCodes.block
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
block: Vale.X64.Decls.va_codes -> Vale.X64.Decls.va_code
{ "end_col": 27, "end_line": 168, "start_col": 19, "start_line": 168 }
Prims.GTot
val precedes_wrap (#a: Type) (x y: a) : GTot Type0
[ { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y
val precedes_wrap (#a: Type) (x y: a) : GTot Type0 let precedes_wrap (#a: Type) (x y: a) : GTot Type0 =
false
null
false
precedes x y
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "sometrivial" ]
[ "Prims.precedes" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val precedes_wrap (#a: Type) (x y: a) : GTot Type0
[]
Vale.X64.QuickCodes.precedes_wrap
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: a -> y: a -> Prims.GTot Type0
{ "end_col": 63, "end_line": 35, "start_col": 51, "start_line": 35 }
Prims.Tot
val wp_While (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g0: a) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k)
val wp_While (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g0: a) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 let wp_While (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g0: a) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 =
false
null
false
inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ (forall (s1: va_state) (g1: a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCodes.cmp", "Vale.X64.QuickCode.quickCode", "Vale.X64.QuickCode.mods_t", "Vale.X64.Decls.va_state", "Prims.l_and", "Prims.b2t", "Vale.X64.QuickCodes.mods_contains", "Vale.X64.QuickCode.__proj__QProc__item__mods", "Vale.X64.QuickCodes.mods_contains1", "Vale.X64.QuickCode.Mod_flags", "Prims.l_Forall", "Prims.l_imp", "Vale.X64.QuickCodes.wp_While_body" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0)
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_While (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g0: a) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[]
Vale.X64.QuickCodes.wp_While
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.QuickCodes.cmp -> qc: (_: a -> Vale.X64.QuickCode.quickCode a c) -> mods: Vale.X64.QuickCode.mods_t -> inv: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> dec: (_: Vale.X64.Decls.va_state -> _: a -> d) -> g0: a -> s0: Vale.X64.Decls.va_state -> k: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> Type0
{ "end_col": 86, "end_line": 287, "start_col": 2, "start_line": 285 }
Prims.Tot
val wp_InlineIf (#a: Type) (#c1 #c2: code) (b: bool) (qc1: quickCode a c1) (qc2: quickCode a c2) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k)
val wp_InlineIf (#a: Type) (#c1 #c2: code) (b: bool) (qc1: quickCode a c1) (qc2: quickCode a c2) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 let wp_InlineIf (#a: Type) (#c1 #c2: code) (b: bool) (qc1: quickCode a c1) (qc2: quickCode a c2) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 =
false
null
false
(b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Prims.bool", "Vale.X64.QuickCode.quickCode", "Vale.X64.QuickCode.mods_t", "Vale.X64.Decls.va_state", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Vale.X64.QuickCodes.mods_contains", "Vale.X64.QuickCode.__proj__QProc__item__mods", "Vale.X64.QuickCode.__proj__QProc__item__wp", "Prims.op_Negation" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 =
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_InlineIf (#a: Type) (#c1 #c2: code) (b: bool) (qc1: quickCode a c1) (qc2: quickCode a c2) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[]
Vale.X64.QuickCodes.wp_InlineIf
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Prims.bool -> qc1: Vale.X64.QuickCode.quickCode a c1 -> qc2: Vale.X64.QuickCode.quickCode a c2 -> mods: Vale.X64.QuickCode.mods_t -> s0: Vale.X64.Decls.va_state -> k: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> Type0
{ "end_col": 63, "end_line": 191, "start_col": 2, "start_line": 190 }
Prims.Tot
val va_QSeq (#a: Type0) (#b: Type) (#c: code) (#cs: codes) (r: range) (msg: string) (qc: quickCode b c) (qcs: quickCodes a cs) : quickCodes a (c :: cs)
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs
val va_QSeq (#a: Type0) (#b: Type) (#c: code) (#cs: codes) (r: range) (msg: string) (qc: quickCode b c) (qcs: quickCodes a cs) : quickCodes a (c :: cs) let va_QSeq (#a: Type0) (#b: Type) (#c: code) (#cs: codes) (r: range) (msg: string) (qc: quickCode b c) (qcs: quickCodes a cs) : quickCodes a (c :: cs) =
false
null
false
QSeq r msg qc qcs
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCodes.codes", "FStar.Range.range", "Prims.string", "Vale.X64.QuickCode.quickCode", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCodes.QSeq", "Prims.Cons", "Vale.X64.Decls.va_code" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_QSeq (#a: Type0) (#b: Type) (#c: code) (#cs: codes) (r: range) (msg: string) (qc: quickCode b c) (qcs: quickCodes a cs) : quickCodes a (c :: cs)
[]
Vale.X64.QuickCodes.va_QSeq
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> qc: Vale.X64.QuickCode.quickCode b c -> qcs: Vale.X64.QuickCodes.quickCodes a cs -> Vale.X64.QuickCodes.quickCodes a (c :: cs)
{ "end_col": 180, "end_line": 75, "start_col": 163, "start_line": 75 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let k_AssertBy (p:Type0) (_:va_state) () = p
let k_AssertBy (p: Type0) (_: va_state) () =
false
null
false
p
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_state", "Prims.unit" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val k_AssertBy : p: Type0 -> _: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0
[]
Vale.X64.QuickCodes.k_AssertBy
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Type0 -> _: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0
{ "end_col": 44, "end_line": 101, "start_col": 43, "start_line": 101 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p)
let tAssertLemma (p: Type0) =
false
null
false
unit -> Lemma (requires p) (ensures p)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Prims.unit", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tAssertLemma : p: Type0 -> Type0
[]
Vale.X64.QuickCodes.tAssertLemma
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Type0 -> Type0
{ "end_col": 67, "end_line": 308, "start_col": 29, "start_line": 308 }
Prims.Tot
val wp_If (#a: Type) (#c1 #c2: code) (b: cmp) (qc1: quickCode a c1) (qc2: quickCode a c2) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k))
val wp_If (#a: Type) (#c1 #c2: code) (b: cmp) (qc1: quickCode a c1) (qc2: quickCode a c2) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 let wp_If (#a: Type) (#c1 #c2: code) (b: cmp) (qc1: quickCode a c1) (qc2: quickCode a c2) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 =
false
null
false
valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in (eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k))
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCodes.cmp", "Vale.X64.QuickCode.quickCode", "Vale.X64.QuickCode.mods_t", "Vale.X64.Decls.va_state", "Prims.l_and", "Vale.X64.QuickCodes.valid_cmp", "Prims.b2t", "Vale.X64.QuickCodes.mods_contains1", "Vale.X64.QuickCode.Mod_flags", "Prims.l_imp", "Vale.X64.QuickCodes.eval_cmp", "Vale.X64.QuickCodes.mods_contains", "Vale.X64.QuickCode.__proj__QProc__item__mods", "Vale.X64.QuickCode.__proj__QProc__item__wp", "Prims.op_Negation", "Vale.X64.State.vale_state", "Vale.X64.Decls.va_upd_flags", "Vale.X64.Decls.havoc_flags" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 =
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_If (#a: Type) (#c1 #c2: code) (b: cmp) (qc1: quickCode a c1) (qc2: quickCode a c2) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[]
Vale.X64.QuickCodes.wp_If
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.QuickCodes.cmp -> qc1: Vale.X64.QuickCode.quickCode a c1 -> qc2: Vale.X64.QuickCode.quickCode a c2 -> mods: Vale.X64.QuickCode.mods_t -> s0: Vale.X64.Decls.va_state -> k: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> Type0
{ "end_col": 80, "end_line": 248, "start_col": 2, "start_line": 245 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p)
let tAssumeLemma (p: Type0) =
false
null
false
unit -> Lemma (requires True) (ensures p)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tAssumeLemma : p: Type0 -> Type0
[]
Vale.X64.QuickCodes.tAssumeLemma
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Type0 -> Type0
{ "end_col": 70, "end_line": 315, "start_col": 29, "start_line": 315 }
Prims.Tot
val normal_steps:list string
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let normal_steps : list string = [ `%Mkvale_state?.vs_ok; `%Mkvale_state?.vs_regs; `%Mkvale_state?.vs_flags; `%Mkvale_state?.vs_heap; `%Mkvale_state?.vs_stack; `%Mkvale_state?.vs_stackTaint; `%Mkvale_full_heap?.vf_layout; `%Mkvale_full_heap?.vf_heap; `%Mkvale_full_heap?.vf_heaplets; `%QProc?.wp; `%QProc?.mods; `%OConst?; `%OReg?; `%OMem?; `%OStack?; `%FStar.FunctionalExtensionality.on_dom; ]
val normal_steps:list string let normal_steps:list string =
false
null
false
[ `%Mkvale_state?.vs_ok; `%Mkvale_state?.vs_regs; `%Mkvale_state?.vs_flags; `%Mkvale_state?.vs_heap; `%Mkvale_state?.vs_stack; `%Mkvale_state?.vs_stackTaint; `%Mkvale_full_heap?.vf_layout; `%Mkvale_full_heap?.vf_heap; `%Mkvale_full_heap?.vf_heaplets; `%QProc?.wp; `%QProc?.mods; `%OConst?; `%OReg?; `%OMem?; `%OStack?; `%FStar.FunctionalExtensionality.on_dom ]
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr] let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1) [@va_qattr] let rec regs_match (r0:Regs.t) (r1:Regs.t) (k:nat{k <= n_reg_files}) : Type0 = if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1) [@va_qattr] let all_regs_match (r0:Regs.t) (r1:Regs.t) : Type0 = regs_match r0 r1 n_reg_files [@va_qattr] let state_match (s0:va_state) (s1:va_state) : Type0 = s0.vs_ok == s1.vs_ok /\ all_regs_match s0.vs_regs s1.vs_regs /\ s0.vs_flags == s1.vs_flags /\ s0.vs_heap == s1.vs_heap /\ s0.vs_stack == s1.vs_stack /\ s0.vs_stackTaint == s1.vs_stackTaint val lemma_state_match (s0:va_state) (s1:va_state) : Lemma (requires state_match s0 s1) (ensures state_eq s0 s1) [@va_qattr] let va_state_match (s0:va_state) (s1:va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1) = FStar.Classical.move_requires (lemma_state_match s0) s1; state_match s0 s1 [@va_qattr] unfold let wp_sound_code_pre (#a:Type0) (#c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) : Type0 = forall (ok:bool) (regs:Regs.t) (flags:Flags.t) //(mem:vale_full_heap) // splitting mem into its components makes the VCs slightly cleaner: (mem_layout:vale_heap_layout) (mem_heap:vale_heap) (mem_heaplets:vale_heaplets) (stack:vale_stack) (stackTaint:memtaint) . let mem = { vf_layout = mem_layout; vf_heap = mem_heap; vf_heaplets = mem_heaplets; } in let s0' = { vs_ok = ok; vs_regs = regs; vs_flags = flags; vs_heap = mem; vs_stack = stack; vs_stackTaint = stackTaint } in s0 == s0' ==> QProc?.wp qc (state_eta s0') (k (state_eta s0')) unfold let wp_sound_code_post (#a:Type0) (#c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) ((sN:va_state), (fN:fuel), (gN:a)) : Type0 = eval c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k s0 sN gN
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val normal_steps:list string
[]
Vale.X64.QuickCodes.normal_steps
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.list Prims.string
{ "end_col": 3, "end_line": 439, "start_col": 2, "start_line": 422 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p)
let tAssertSquashLemma (p: Type0) =
false
null
false
unit -> Ghost (squash p) (requires p) (ensures fun () -> p)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Prims.unit", "Prims.squash" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tAssertSquashLemma : p: Type0 -> Type0
[]
Vale.X64.QuickCodes.tAssertSquashLemma
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
p: Type0 -> Type0
{ "end_col": 94, "end_line": 322, "start_col": 35, "start_line": 322 }
Prims.Tot
val va_qAssert (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: quickCodes a cs) : quickCodes a cs
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs
val va_qAssert (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: quickCodes a cs) : quickCodes a cs let va_qAssert (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: quickCodes a cs) : quickCodes a cs =
false
null
false
QLemma r msg e (fun () -> e) (qAssertLemma e) qcs
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.codes", "FStar.Range.range", "Prims.string", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCodes.QLemma", "Prims.unit", "Vale.X64.QuickCodes.qAssertLemma" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_qAssert (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: quickCodes a cs) : quickCodes a cs
[]
Vale.X64.QuickCodes.va_qAssert
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> e: Type0 -> qcs: Vale.X64.QuickCodes.quickCodes a cs -> Vale.X64.QuickCodes.quickCodes a cs
{ "end_col": 51, "end_line": 313, "start_col": 2, "start_line": 313 }
Prims.Tot
val wp_While_body (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g1: a) (s1: va_state) (k: (va_state -> a -> Type0)) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1))
val wp_While_body (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g1: a) (s1: va_state) (k: (va_state -> a -> Type0)) : Type0 let wp_While_body (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g1: a) (s1: va_state) (k: (va_state -> a -> Type0)) : Type0 =
false
null
false
valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in (eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1))
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCodes.cmp", "Vale.X64.QuickCode.quickCode", "Vale.X64.QuickCode.mods_t", "Vale.X64.Decls.va_state", "Prims.l_and", "Vale.X64.QuickCodes.valid_cmp", "Prims.l_imp", "Prims.b2t", "Vale.X64.QuickCodes.eval_cmp", "Vale.X64.QuickCodes.mods_contains", "Vale.X64.QuickCode.__proj__QProc__item__mods", "Vale.X64.QuickCode.__proj__QProc__item__wp", "Vale.X64.QuickCodes.wp_While_inv", "Prims.op_Negation", "Vale.X64.State.vale_state", "Vale.X64.Decls.va_upd_flags", "Vale.X64.Decls.havoc_flags" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0)
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_While_body (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g1: a) (s1: va_state) (k: (va_state -> a -> Type0)) : Type0
[]
Vale.X64.QuickCodes.wp_While_body
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b: Vale.X64.QuickCodes.cmp -> qc: (_: a -> Vale.X64.QuickCode.quickCode a c) -> mods: Vale.X64.QuickCode.mods_t -> inv: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> dec: (_: Vale.X64.Decls.va_state -> _: a -> d) -> g1: a -> s1: Vale.X64.Decls.va_state -> k: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> Type0
{ "end_col": 39, "end_line": 278, "start_col": 2, "start_line": 275 }
Prims.Tot
val wp_While_inv (#a #d: Type) (#c: code) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (s1: va_state) (g1: a) (s2: va_state) (g2: a) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1
val wp_While_inv (#a #d: Type) (#c: code) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (s1: va_state) (g1: a) (s2: va_state) (g2: a) : Type0 let wp_While_inv (#a #d: Type) (#c: code) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (s1: va_state) (g1: a) (s2: va_state) (g2: a) : Type0 =
false
null
false
s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCode.quickCode", "Vale.X64.QuickCode.mods_t", "Vale.X64.Decls.va_state", "Prims.l_and", "Prims.b2t", "Vale.X64.State.__proj__Mkvale_state__item__vs_ok", "Vale.X64.QuickCodes.mods_contains", "Vale.X64.QuickCode.__proj__QProc__item__mods", "Prims.precedes" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a)
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_While_inv (#a #d: Type) (#c: code) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (s1: va_state) (g1: a) (s2: va_state) (g2: a) : Type0
[]
Vale.X64.QuickCodes.wp_While_inv
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
qc: (_: a -> Vale.X64.QuickCode.quickCode a c) -> mods: Vale.X64.QuickCode.mods_t -> inv: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> dec: (_: Vale.X64.Decls.va_state -> _: a -> d) -> s1: Vale.X64.Decls.va_state -> g1: a -> s2: Vale.X64.Decls.va_state -> g2: a -> Type0
{ "end_col": 84, "end_line": 268, "start_col": 2, "start_line": 268 }
Prims.Tot
val normal (x: Type0) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let normal (x:Type0) : Type0 = norm [nbe; iota; zeta; simplify; primops; delta_attr [`%va_qattr]; delta_only normal_steps] x
val normal (x: Type0) : Type0 let normal (x: Type0) : Type0 =
false
null
false
norm [nbe; iota; zeta; simplify; primops; delta_attr [`%va_qattr]; delta_only normal_steps] x
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "FStar.Pervasives.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.nbe", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.Pervasives.simplify", "FStar.Pervasives.primops", "FStar.Pervasives.delta_attr", "Prims.string", "Prims.Nil", "FStar.Pervasives.delta_only", "Vale.X64.QuickCodes.normal_steps" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr] let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1) [@va_qattr] let rec regs_match (r0:Regs.t) (r1:Regs.t) (k:nat{k <= n_reg_files}) : Type0 = if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1) [@va_qattr] let all_regs_match (r0:Regs.t) (r1:Regs.t) : Type0 = regs_match r0 r1 n_reg_files [@va_qattr] let state_match (s0:va_state) (s1:va_state) : Type0 = s0.vs_ok == s1.vs_ok /\ all_regs_match s0.vs_regs s1.vs_regs /\ s0.vs_flags == s1.vs_flags /\ s0.vs_heap == s1.vs_heap /\ s0.vs_stack == s1.vs_stack /\ s0.vs_stackTaint == s1.vs_stackTaint val lemma_state_match (s0:va_state) (s1:va_state) : Lemma (requires state_match s0 s1) (ensures state_eq s0 s1) [@va_qattr] let va_state_match (s0:va_state) (s1:va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1) = FStar.Classical.move_requires (lemma_state_match s0) s1; state_match s0 s1 [@va_qattr] unfold let wp_sound_code_pre (#a:Type0) (#c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) : Type0 = forall (ok:bool) (regs:Regs.t) (flags:Flags.t) //(mem:vale_full_heap) // splitting mem into its components makes the VCs slightly cleaner: (mem_layout:vale_heap_layout) (mem_heap:vale_heap) (mem_heaplets:vale_heaplets) (stack:vale_stack) (stackTaint:memtaint) . let mem = { vf_layout = mem_layout; vf_heap = mem_heap; vf_heaplets = mem_heaplets; } in let s0' = { vs_ok = ok; vs_regs = regs; vs_flags = flags; vs_heap = mem; vs_stack = stack; vs_stackTaint = stackTaint } in s0 == s0' ==> QProc?.wp qc (state_eta s0') (k (state_eta s0')) unfold let wp_sound_code_post (#a:Type0) (#c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) ((sN:va_state), (fN:fuel), (gN:a)) : Type0 = eval c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k s0 sN gN unfold let normal_steps : list string = [ `%Mkvale_state?.vs_ok; `%Mkvale_state?.vs_regs; `%Mkvale_state?.vs_flags; `%Mkvale_state?.vs_heap; `%Mkvale_state?.vs_stack; `%Mkvale_state?.vs_stackTaint; `%Mkvale_full_heap?.vf_layout; `%Mkvale_full_heap?.vf_heap; `%Mkvale_full_heap?.vf_heaplets; `%QProc?.wp; `%QProc?.mods; `%OConst?; `%OReg?; `%OMem?; `%OStack?; `%FStar.FunctionalExtensionality.on_dom; ]
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val normal (x: Type0) : Type0
[]
Vale.X64.QuickCodes.normal
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Type0 -> Type0
{ "end_col": 131, "end_line": 441, "start_col": 38, "start_line": 441 }
Prims.Tot
val va_qAssume (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: quickCodes a cs) : quickCodes a cs
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs
val va_qAssume (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: quickCodes a cs) : quickCodes a cs let va_qAssume (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: quickCodes a cs) : quickCodes a cs =
false
null
false
QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.codes", "FStar.Range.range", "Prims.string", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCodes.QLemma", "Prims.l_True", "Prims.unit", "Vale.X64.QuickCodes.qAssumeLemma" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_qAssume (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: quickCodes a cs) : quickCodes a cs
[]
Vale.X64.QuickCodes.va_qAssume
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> e: Type0 -> qcs: Vale.X64.QuickCodes.quickCodes a cs -> Vale.X64.QuickCodes.quickCodes a cs
{ "end_col": 54, "end_line": 320, "start_col": 2, "start_line": 320 }
Prims.Tot
val va_qAssertBy (#a: Type) (#cs: codes) (r: range) (msg: string) (p: Type0) (qcsBy: quickCodes unit []) (qcsTail: quickCodes a cs) : quickCodes a cs
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail
val va_qAssertBy (#a: Type) (#cs: codes) (r: range) (msg: string) (p: Type0) (qcsBy: quickCodes unit []) (qcsTail: quickCodes a cs) : quickCodes a cs let va_qAssertBy (#a: Type) (#cs: codes) (r: range) (msg: string) (p: Type0) (qcsBy: quickCodes unit []) (qcsTail: quickCodes a cs) : quickCodes a cs =
false
null
false
QAssertBy r msg p qcsBy qcsTail
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.codes", "FStar.Range.range", "Prims.string", "Vale.X64.QuickCodes.quickCodes", "Prims.unit", "Prims.Nil", "Vale.X64.Machine_s.precode", "Vale.X64.Decls.ins", "Vale.X64.Decls.ocmp", "Vale.X64.QuickCodes.QAssertBy" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_qAssertBy (#a: Type) (#cs: codes) (r: range) (msg: string) (p: Type0) (qcsBy: quickCodes unit []) (qcsTail: quickCodes a cs) : quickCodes a cs
[]
Vale.X64.QuickCodes.va_qAssertBy
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> p: Type0 -> qcsBy: Vale.X64.QuickCodes.quickCodes Prims.unit [] -> qcsTail: Vale.X64.QuickCodes.quickCodes a cs -> Vale.X64.QuickCodes.quickCodes a cs
{ "end_col": 33, "end_line": 341, "start_col": 2, "start_line": 341 }
Prims.Tot
val state_match (s0 s1: va_state) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let state_match (s0:va_state) (s1:va_state) : Type0 = s0.vs_ok == s1.vs_ok /\ all_regs_match s0.vs_regs s1.vs_regs /\ s0.vs_flags == s1.vs_flags /\ s0.vs_heap == s1.vs_heap /\ s0.vs_stack == s1.vs_stack /\ s0.vs_stackTaint == s1.vs_stackTaint
val state_match (s0 s1: va_state) : Type0 let state_match (s0 s1: va_state) : Type0 =
false
null
false
s0.vs_ok == s1.vs_ok /\ all_regs_match s0.vs_regs s1.vs_regs /\ s0.vs_flags == s1.vs_flags /\ s0.vs_heap == s1.vs_heap /\ s0.vs_stack == s1.vs_stack /\ s0.vs_stackTaint == s1.vs_stackTaint
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Decls.va_state", "Prims.l_and", "Prims.eq2", "Prims.bool", "Vale.X64.State.__proj__Mkvale_state__item__vs_ok", "Vale.X64.QuickCodes.all_regs_match", "Vale.X64.State.__proj__Mkvale_state__item__vs_regs", "Vale.X64.Flags.t", "Vale.X64.State.__proj__Mkvale_state__item__vs_flags", "Vale.X64.Memory.vale_full_heap", "Vale.X64.State.__proj__Mkvale_state__item__vs_heap", "Vale.X64.Stack_i.vale_stack", "Vale.X64.State.__proj__Mkvale_state__item__vs_stack", "Vale.X64.Memory.memtaint", "Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr] let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1) [@va_qattr] let rec regs_match (r0:Regs.t) (r1:Regs.t) (k:nat{k <= n_reg_files}) : Type0 = if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1) [@va_qattr] let all_regs_match (r0:Regs.t) (r1:Regs.t) : Type0 = regs_match r0 r1 n_reg_files [@va_qattr]
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val state_match (s0 s1: va_state) : Type0
[]
Vale.X64.QuickCodes.state_match
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s0: Vale.X64.Decls.va_state -> s1: Vale.X64.Decls.va_state -> Type0
{ "end_col": 38, "end_line": 373, "start_col": 2, "start_line": 368 }
Prims.Tot
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_sound_code_post (#a:Type0) (#c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) ((sN:va_state), (fN:fuel), (gN:a)) : Type0 = eval c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k s0 sN gN
let wp_sound_code_post (#a: Type0) (#c: code) (qc: quickCode a c) (s0: va_state) (k: (s0': va_state{s0 == s0'} -> va_state -> a -> Type0)) ((sN: va_state), (fN: fuel), (gN: a)) : Type0 =
false
null
false
eval c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k s0 sN gN
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCode.quickCode", "Vale.X64.Decls.va_state", "Prims.eq2", "FStar.Pervasives.Native.tuple3", "Vale.X64.State.vale_state", "Vale.X64.Decls.va_fuel", "Prims.l_and", "Vale.X64.QuickCodes.eval", "Vale.X64.QuickCode.update_state_mods", "Vale.X64.QuickCode.__proj__QProc__item__mods", "Vale.X64.Decls.state_inv" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr] let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1) [@va_qattr] let rec regs_match (r0:Regs.t) (r1:Regs.t) (k:nat{k <= n_reg_files}) : Type0 = if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1) [@va_qattr] let all_regs_match (r0:Regs.t) (r1:Regs.t) : Type0 = regs_match r0 r1 n_reg_files [@va_qattr] let state_match (s0:va_state) (s1:va_state) : Type0 = s0.vs_ok == s1.vs_ok /\ all_regs_match s0.vs_regs s1.vs_regs /\ s0.vs_flags == s1.vs_flags /\ s0.vs_heap == s1.vs_heap /\ s0.vs_stack == s1.vs_stack /\ s0.vs_stackTaint == s1.vs_stackTaint val lemma_state_match (s0:va_state) (s1:va_state) : Lemma (requires state_match s0 s1) (ensures state_eq s0 s1) [@va_qattr] let va_state_match (s0:va_state) (s1:va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1) = FStar.Classical.move_requires (lemma_state_match s0) s1; state_match s0 s1 [@va_qattr] unfold let wp_sound_code_pre (#a:Type0) (#c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) : Type0 = forall (ok:bool) (regs:Regs.t) (flags:Flags.t) //(mem:vale_full_heap) // splitting mem into its components makes the VCs slightly cleaner: (mem_layout:vale_heap_layout) (mem_heap:vale_heap) (mem_heaplets:vale_heaplets) (stack:vale_stack) (stackTaint:memtaint) . let mem = { vf_layout = mem_layout; vf_heap = mem_heap; vf_heaplets = mem_heaplets; } in let s0' = { vs_ok = ok; vs_regs = regs; vs_flags = flags; vs_heap = mem; vs_stack = stack; vs_stackTaint = stackTaint } in s0 == s0' ==> QProc?.wp qc (state_eta s0') (k (state_eta s0'))
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_sound_code_post : qc: Vale.X64.QuickCode.quickCode a c -> s0: Vale.X64.Decls.va_state -> k: (s0': Vale.X64.Decls.va_state{s0 == s0'} -> _: Vale.X64.Decls.va_state -> _: a -> Type0) -> _: ((Vale.X64.State.vale_state * Vale.X64.Decls.va_fuel) * a) -> Type0
[]
Vale.X64.QuickCodes.wp_sound_code_post
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
qc: Vale.X64.QuickCode.quickCode a c -> s0: Vale.X64.Decls.va_state -> k: (s0': Vale.X64.Decls.va_state{s0 == s0'} -> _: Vale.X64.Decls.va_state -> _: a -> Type0) -> _: ((Vale.X64.State.vale_state * Vale.X64.Decls.va_fuel) * a) -> Type0
{ "end_col": 12, "end_line": 419, "start_col": 2, "start_line": 416 }
Prims.Tot
val va_QEmpty (#a: Type0) (v: a) : quickCodes a []
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v
val va_QEmpty (#a: Type0) (v: a) : quickCodes a [] let va_QEmpty (#a: Type0) (v: a) : quickCodes a [] =
false
null
false
QEmpty v
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.QEmpty", "Vale.X64.QuickCodes.quickCodes", "Prims.Nil", "Vale.X64.Machine_s.precode", "Vale.X64.Decls.ins", "Vale.X64.Decls.ocmp" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_QEmpty (#a: Type0) (v: a) : quickCodes a []
[]
Vale.X64.QuickCodes.va_QEmpty
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
v: a -> Vale.X64.QuickCodes.quickCodes a []
{ "end_col": 78, "end_line": 73, "start_col": 70, "start_line": 73 }
Prims.Tot
val wp_block (#a: Type) (#cs: codes) (qcs: (va_state -> GTot (quickCodes a cs))) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0
val wp_block (#a: Type) (#cs: codes) (qcs: (va_state -> GTot (quickCodes a cs))) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 let wp_block (#a: Type) (#cs: codes) (qcs: (va_state -> GTot (quickCodes a cs))) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0 =
false
null
false
wp cs (qcs s0) mods k s0
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.codes", "Vale.X64.Decls.va_state", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCode.mods_t", "Vale.X64.QuickCodes.wp" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_block (#a: Type) (#cs: codes) (qcs: (va_state -> GTot (quickCodes a cs))) (mods: mods_t) (s0: va_state) (k: (va_state -> a -> Type0)) : Type0
[]
Vale.X64.QuickCodes.wp_block
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
qcs: (_: Vale.X64.Decls.va_state -> Prims.GTot (Vale.X64.QuickCodes.quickCodes a cs)) -> mods: Vale.X64.QuickCode.mods_t -> s0: Vale.X64.Decls.va_state -> k: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> Type0
{ "end_col": 26, "end_line": 172, "start_col": 2, "start_line": 172 }
Prims.Tot
val va_qAssertSquash (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: (squash e -> GTot (quickCodes a cs))) : quickCodes a ((Block []) :: cs)
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs
val va_qAssertSquash (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: (squash e -> GTot (quickCodes a cs))) : quickCodes a ((Block []) :: cs) let va_qAssertSquash (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: (squash e -> GTot (quickCodes a cs))) : quickCodes a ((Block []) :: cs) =
false
null
false
QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.codes", "FStar.Range.range", "Prims.string", "Prims.squash", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCodes.QGhost", "Prims.unit", "Vale.X64.QuickCodes.qAssertSquashLemma", "Prims.Cons", "Vale.X64.Decls.va_code", "Vale.X64.Machine_s.Block", "Vale.X64.Decls.ins", "Vale.X64.Decls.ocmp", "Prims.Nil", "Vale.X64.Machine_s.precode" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs))
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_qAssertSquash (#a: Type) (#cs: codes) (r: range) (msg: string) (e: Type0) (qcs: (squash e -> GTot (quickCodes a cs))) : quickCodes a ((Block []) :: cs)
[]
Vale.X64.QuickCodes.va_qAssertSquash
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> e: Type0 -> qcs: (_: Prims.squash e -> Prims.GTot (Vale.X64.QuickCodes.quickCodes a cs)) -> Vale.X64.QuickCodes.quickCodes a (Vale.X64.Machine_s.Block [] :: cs)
{ "end_col": 68, "end_line": 329, "start_col": 2, "start_line": 329 }
Prims.Ghost
val label (r: range) (msg: string) (p: Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p)
[ { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p
val label (r: range) (msg: string) (p: Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) let label (r: range) (msg: string) (p: Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) =
false
null
false
assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[]
[ "FStar.Range.range", "Prims.string", "Vale.X64.QuickCodes.labeled_wrap", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.l_iff", "Prims.l_True" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val label (r: range) (msg: string) (p: Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p)
[]
Vale.X64.QuickCodes.label
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> p: Type0 -> Prims.Ghost Type0
{ "end_col": 22, "end_line": 27, "start_col": 2, "start_line": 26 }
Prims.Tot
val mods_contains1 (allowed: mods_t) (found: mod_t) : bool
[ { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found
val mods_contains1 (allowed: mods_t) (found: mod_t) : bool let rec mods_contains1 (allowed: mods_t) (found: mod_t) : bool =
false
null
false
match allowed with | [] -> mod_eq Mod_None found | h :: t -> mod_eq h found || mods_contains1 t found
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCode.mods_t", "Vale.X64.QuickCode.mod_t", "Vale.X64.QuickCode.mod_eq", "Vale.X64.QuickCode.Mod_None", "Prims.list", "Prims.op_BarBar", "Vale.X64.QuickCodes.mods_contains1", "Prims.bool" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr]
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mods_contains1 (allowed: mods_t) (found: mod_t) : bool
[ "recursion" ]
Vale.X64.QuickCodes.mods_contains1
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
allowed: Vale.X64.QuickCode.mods_t -> found: Vale.X64.QuickCode.mod_t -> Prims.bool
{ "end_col": 52, "end_line": 41, "start_col": 2, "start_line": 39 }
Prims.Tot
val mods_contains (allowed found: mods_t) : bool
[ { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t
val mods_contains (allowed found: mods_t) : bool let rec mods_contains (allowed found: mods_t) : bool =
false
null
false
match found with | [] -> true | h :: t -> mods_contains1 allowed h && mods_contains allowed t
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCode.mods_t", "Vale.X64.QuickCode.mod_t", "Prims.list", "Prims.op_AmpAmp", "Vale.X64.QuickCodes.mods_contains1", "Vale.X64.QuickCodes.mods_contains", "Prims.bool" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr]
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mods_contains (allowed found: mods_t) : bool
[ "recursion" ]
Vale.X64.QuickCodes.mods_contains
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
allowed: Vale.X64.QuickCode.mods_t -> found: Vale.X64.QuickCode.mods_t -> Prims.bool
{ "end_col": 63, "end_line": 47, "start_col": 2, "start_line": 45 }
Prims.Tot
val qblock (#a: Type) (#cs: codes) (mods: mods_t) (qcs: (va_state -> GTot (quickCodes a cs))) : quickCode a (block cs)
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods)
val qblock (#a: Type) (#cs: codes) (mods: mods_t) (qcs: (va_state -> GTot (quickCodes a cs))) : quickCode a (block cs) let qblock (#a: Type) (#cs: codes) (mods: mods_t) (qcs: (va_state -> GTot (quickCodes a cs))) : quickCode a (block cs) =
false
null
false
QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.codes", "Vale.X64.QuickCode.mods_t", "Vale.X64.Decls.va_state", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCode.QProc", "Vale.X64.QuickCodes.block", "Vale.X64.QuickCodes.wp_block", "Vale.X64.QuickCodes.qblock_proof", "Vale.X64.QuickCode.quickCode" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val qblock (#a: Type) (#cs: codes) (mods: mods_t) (qcs: (va_state -> GTot (quickCodes a cs))) : quickCode a (block cs)
[]
Vale.X64.QuickCodes.qblock
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mods: Vale.X64.QuickCode.mods_t -> qcs: (_: Vale.X64.Decls.va_state -> Prims.GTot (Vale.X64.QuickCodes.quickCodes a cs)) -> Vale.X64.QuickCode.quickCode a (Vale.X64.QuickCodes.block cs)
{ "end_col": 67, "end_line": 183, "start_col": 2, "start_line": 183 }
Prims.Tot
val va_qInlineIf (#a: Type) (#c1 #c2: code) (mods: mods_t) (b: bool) (qc1: quickCode a c1) (qc2: quickCode a c2) : quickCode a (if_code b c1 c2)
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods)
val va_qInlineIf (#a: Type) (#c1 #c2: code) (mods: mods_t) (b: bool) (qc1: quickCode a c1) (qc2: quickCode a c2) : quickCode a (if_code b c1 c2) let va_qInlineIf (#a: Type) (#c1 #c2: code) (mods: mods_t) (b: bool) (qc1: quickCode a c1) (qc2: quickCode a c2) : quickCode a (if_code b c1 c2) =
false
null
false
QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCode.mods_t", "Prims.bool", "Vale.X64.QuickCode.quickCode", "Vale.X64.QuickCode.QProc", "Vale.X64.QuickCodes.if_code", "Vale.X64.QuickCodes.wp_InlineIf", "Vale.X64.QuickCodes.qInlineIf_proof" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_qInlineIf (#a: Type) (#c1 #c2: code) (mods: mods_t) (b: bool) (qc1: quickCode a c1) (qc2: quickCode a c2) : quickCode a (if_code b c1 c2)
[]
Vale.X64.QuickCodes.va_qInlineIf
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mods: Vale.X64.QuickCode.mods_t -> b: Prims.bool -> qc1: Vale.X64.QuickCode.quickCode a c1 -> qc2: Vale.X64.QuickCode.quickCode a c2 -> Vale.X64.QuickCode.quickCode a (Vale.X64.QuickCodes.if_code b c1 c2)
{ "end_col": 92, "end_line": 202, "start_col": 2, "start_line": 202 }
Prims.Tot
val va_QLemma (#a: Type0) (#cs: codes) (r: range) (msg: string) (pre: Type0) (post: (squash pre -> Type0)) (l: (unit -> Lemma (requires pre) (ensures post ()))) (qcs: quickCodes a cs) : quickCodes a cs
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs
val va_QLemma (#a: Type0) (#cs: codes) (r: range) (msg: string) (pre: Type0) (post: (squash pre -> Type0)) (l: (unit -> Lemma (requires pre) (ensures post ()))) (qcs: quickCodes a cs) : quickCodes a cs let va_QLemma (#a: Type0) (#cs: codes) (r: range) (msg: string) (pre: Type0) (post: (squash pre -> Type0)) (l: (unit -> Lemma (requires pre) (ensures post ()))) (qcs: quickCodes a cs) : quickCodes a cs =
false
null
false
QLemma r msg pre post l qcs
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.codes", "FStar.Range.range", "Prims.string", "Prims.squash", "Prims.unit", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCodes.QLemma" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_QLemma (#a: Type0) (#cs: codes) (r: range) (msg: string) (pre: Type0) (post: (squash pre -> Type0)) (l: (unit -> Lemma (requires pre) (ensures post ()))) (qcs: quickCodes a cs) : quickCodes a cs
[]
Vale.X64.QuickCodes.va_QLemma
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> pre: Type0 -> post: (_: Prims.squash pre -> Type0) -> l: (_: Prims.unit -> FStar.Pervasives.Lemma (requires pre) (ensures post ())) -> qcs: Vale.X64.QuickCodes.quickCodes a cs -> Vale.X64.QuickCodes.quickCodes a cs
{ "end_col": 240, "end_line": 74, "start_col": 213, "start_line": 74 }
Prims.Tot
val va_qPURE (#cs: codes) (#pre: ((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a: Type0) (r: range) (msg: string) ($l: (unit -> PURE unit (intro_pure_wp_monotonicity pre; pre))) (qcs: quickCodes a cs) : quickCodes a cs
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs
val va_qPURE (#cs: codes) (#pre: ((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a: Type0) (r: range) (msg: string) ($l: (unit -> PURE unit (intro_pure_wp_monotonicity pre; pre))) (qcs: quickCodes a cs) : quickCodes a cs let va_qPURE (#cs: codes) (#pre: ((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a: Type0) (r: range) (msg: string) ($l: (unit -> PURE unit (intro_pure_wp_monotonicity pre; pre))) (qcs: quickCodes a cs) : quickCodes a cs =
false
null
false
QPURE r msg pre l qcs
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.codes", "Prims.unit", "FStar.Monotonic.Pure.is_monotonic", "FStar.Range.range", "Prims.string", "FStar.Monotonic.Pure.intro_pure_wp_monotonicity", "Vale.X64.QuickCodes.quickCodes", "Vale.X64.QuickCodes.QPURE" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs)
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_qPURE (#cs: codes) (#pre: ((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a: Type0) (r: range) (msg: string) ($l: (unit -> PURE unit (intro_pure_wp_monotonicity pre; pre))) (qcs: quickCodes a cs) : quickCodes a cs
[]
Vale.X64.QuickCodes.va_qPURE
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r: FStar.Range.range -> msg: Prims.string -> $l: (_: Prims.unit -> Prims.PURE Prims.unit) -> qcs: Vale.X64.QuickCodes.quickCodes a cs -> Vale.X64.QuickCodes.quickCodes a cs
{ "end_col": 23, "end_line": 82, "start_col": 2, "start_line": 82 }
Prims.Tot
val all_regs_match (r0 r1: Regs.t) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let all_regs_match (r0:Regs.t) (r1:Regs.t) : Type0 = regs_match r0 r1 n_reg_files
val all_regs_match (r0 r1: Regs.t) : Type0 let all_regs_match (r0 r1: Regs.t) : Type0 =
false
null
false
regs_match r0 r1 n_reg_files
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Regs.t", "Vale.X64.QuickCodes.regs_match", "Vale.X64.Machine_s.n_reg_files" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr] let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1) [@va_qattr] let rec regs_match (r0:Regs.t) (r1:Regs.t) (k:nat{k <= n_reg_files}) : Type0 = if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1) [@va_qattr]
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val all_regs_match (r0 r1: Regs.t) : Type0
[]
Vale.X64.QuickCodes.all_regs_match
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r0: Vale.X64.Regs.t -> r1: Vale.X64.Regs.t -> Type0
{ "end_col": 30, "end_line": 364, "start_col": 2, "start_line": 364 }
Prims.Tot
val va_qIf (#a: Type) (#c1 #c2: code) (mods: mods_t) (b: cmp) (qc1: quickCode a c1) (qc2: quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2)
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods)
val va_qIf (#a: Type) (#c1 #c2: code) (mods: mods_t) (b: cmp) (qc1: quickCode a c1) (qc2: quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) let va_qIf (#a: Type) (#c1 #c2: code) (mods: mods_t) (b: cmp) (qc1: quickCode a c1) (qc2: quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) =
false
null
false
QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCode.mods_t", "Vale.X64.QuickCodes.cmp", "Vale.X64.QuickCode.quickCode", "Vale.X64.QuickCode.QProc", "Vale.X64.Machine_s.IfElse", "Vale.X64.Decls.ins", "Vale.X64.Decls.ocmp", "Vale.X64.QuickCodes.cmp_to_ocmp", "Vale.X64.QuickCodes.wp_If", "Vale.X64.QuickCodes.qIf_proof" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_qIf (#a: Type) (#c1 #c2: code) (mods: mods_t) (b: cmp) (qc1: quickCode a c1) (qc2: quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2)
[]
Vale.X64.QuickCodes.va_qIf
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mods: Vale.X64.QuickCode.mods_t -> b: Vale.X64.QuickCodes.cmp -> qc1: Vale.X64.QuickCode.quickCode a c1 -> qc2: Vale.X64.QuickCode.quickCode a c2 -> Vale.X64.QuickCode.quickCode a (Vale.X64.Machine_s.IfElse (Vale.X64.QuickCodes.cmp_to_ocmp b) c1 c2)
{ "end_col": 93, "end_line": 259, "start_col": 2, "start_line": 259 }
Prims.Tot
val va_qWhile (#a #d: Type) (#c: code) (mods: mods_t) (b: cmp) (qc: (a -> quickCode a c)) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g0: a) : quickCode a (While (cmp_to_ocmp b) c)
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0)
val va_qWhile (#a #d: Type) (#c: code) (mods: mods_t) (b: cmp) (qc: (a -> quickCode a c)) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g0: a) : quickCode a (While (cmp_to_ocmp b) c) let va_qWhile (#a #d: Type) (#c: code) (mods: mods_t) (b: cmp) (qc: (a -> quickCode a c)) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g0: a) : quickCode a (While (cmp_to_ocmp b) c) =
false
null
false
QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCode.mods_t", "Vale.X64.QuickCodes.cmp", "Vale.X64.QuickCode.quickCode", "Vale.X64.Decls.va_state", "Vale.X64.QuickCode.QProc", "Vale.X64.Machine_s.While", "Vale.X64.Decls.ins", "Vale.X64.Decls.ocmp", "Vale.X64.QuickCodes.cmp_to_ocmp", "Vale.X64.QuickCodes.wp_While", "Vale.X64.QuickCodes.qWhile_proof" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a)
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_qWhile (#a #d: Type) (#c: code) (mods: mods_t) (b: cmp) (qc: (a -> quickCode a c)) (inv: (va_state -> a -> Type0)) (dec: (va_state -> a -> d)) (g0: a) : quickCode a (While (cmp_to_ocmp b) c)
[]
Vale.X64.QuickCodes.va_qWhile
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
mods: Vale.X64.QuickCode.mods_t -> b: Vale.X64.QuickCodes.cmp -> qc: (_: a -> Vale.X64.QuickCode.quickCode a c) -> inv: (_: Vale.X64.Decls.va_state -> _: a -> Type0) -> dec: (_: Vale.X64.Decls.va_state -> _: a -> d) -> g0: a -> Vale.X64.QuickCode.quickCode a (Vale.X64.Machine_s.While (Vale.X64.QuickCodes.cmp_to_ocmp b) c)
{ "end_col": 39, "end_line": 304, "start_col": 2, "start_line": 303 }
Prims.Tot
val wp_sound_code_pre (#a: Type0) (#c: code) (qc: quickCode a c) (s0: va_state) (k: (s0': va_state{s0 == s0'} -> va_state -> a -> Type0)) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let wp_sound_code_pre (#a:Type0) (#c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) : Type0 = forall (ok:bool) (regs:Regs.t) (flags:Flags.t) //(mem:vale_full_heap) // splitting mem into its components makes the VCs slightly cleaner: (mem_layout:vale_heap_layout) (mem_heap:vale_heap) (mem_heaplets:vale_heaplets) (stack:vale_stack) (stackTaint:memtaint) . let mem = { vf_layout = mem_layout; vf_heap = mem_heap; vf_heaplets = mem_heaplets; } in let s0' = { vs_ok = ok; vs_regs = regs; vs_flags = flags; vs_heap = mem; vs_stack = stack; vs_stackTaint = stackTaint } in s0 == s0' ==> QProc?.wp qc (state_eta s0') (k (state_eta s0'))
val wp_sound_code_pre (#a: Type0) (#c: code) (qc: quickCode a c) (s0: va_state) (k: (s0': va_state{s0 == s0'} -> va_state -> a -> Type0)) : Type0 let wp_sound_code_pre (#a: Type0) (#c: code) (qc: quickCode a c) (s0: va_state) (k: (s0': va_state{s0 == s0'} -> va_state -> a -> Type0)) : Type0 =
false
null
false
forall (ok: bool) (regs: Regs.t) (flags: Flags.t) (mem_layout: vale_heap_layout) (mem_heap: vale_heap) (mem_heaplets: vale_heaplets) (stack: vale_stack) (stackTaint: memtaint). let mem = { vf_layout = mem_layout; vf_heap = mem_heap; vf_heaplets = mem_heaplets } in let s0' = { vs_ok = ok; vs_regs = regs; vs_flags = flags; vs_heap = mem; vs_stack = stack; vs_stackTaint = stackTaint } in s0 == s0' ==> QProc?.wp qc (state_eta s0') (k (state_eta s0'))
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.code", "Vale.X64.QuickCode.quickCode", "Vale.X64.Decls.va_state", "Prims.eq2", "Prims.l_Forall", "Prims.bool", "Vale.X64.Regs.t", "Vale.X64.Flags.t", "Vale.Arch.HeapImpl.vale_heap_layout", "Vale.X64.Decls.vale_heap", "Vale.Arch.HeapImpl.vale_heaplets", "Vale.X64.Stack_i.vale_stack", "Vale.X64.Memory.memtaint", "Prims.l_imp", "Vale.X64.State.vale_state", "Vale.X64.QuickCode.__proj__QProc__item__wp", "Vale.X64.State.state_eta", "Vale.X64.State.Mkvale_state", "Vale.Arch.HeapImpl.vale_full_heap", "Vale.Arch.HeapImpl.Mkvale_full_heap" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr] let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1) [@va_qattr] let rec regs_match (r0:Regs.t) (r1:Regs.t) (k:nat{k <= n_reg_files}) : Type0 = if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1) [@va_qattr] let all_regs_match (r0:Regs.t) (r1:Regs.t) : Type0 = regs_match r0 r1 n_reg_files [@va_qattr] let state_match (s0:va_state) (s1:va_state) : Type0 = s0.vs_ok == s1.vs_ok /\ all_regs_match s0.vs_regs s1.vs_regs /\ s0.vs_flags == s1.vs_flags /\ s0.vs_heap == s1.vs_heap /\ s0.vs_stack == s1.vs_stack /\ s0.vs_stackTaint == s1.vs_stackTaint val lemma_state_match (s0:va_state) (s1:va_state) : Lemma (requires state_match s0 s1) (ensures state_eq s0 s1) [@va_qattr] let va_state_match (s0:va_state) (s1:va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1) = FStar.Classical.move_requires (lemma_state_match s0) s1; state_match s0 s1 [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val wp_sound_code_pre (#a: Type0) (#c: code) (qc: quickCode a c) (s0: va_state) (k: (s0': va_state{s0 == s0'} -> va_state -> a -> Type0)) : Type0
[]
Vale.X64.QuickCodes.wp_sound_code_pre
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
qc: Vale.X64.QuickCode.quickCode a c -> s0: Vale.X64.Decls.va_state -> k: (s0': Vale.X64.Decls.va_state{s0 == s0'} -> _: Vale.X64.Decls.va_state -> _: a -> Type0) -> Type0
{ "end_col": 66, "end_line": 413, "start_col": 2, "start_line": 389 }
Prims.Tot
val regs_match_file (r0 r1: Regs.t) (rf: reg_file_id) (k: nat{k <= n_regs rf}) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1)
val regs_match_file (r0 r1: Regs.t) (rf: reg_file_id) (k: nat{k <= n_regs rf}) : Type0 let rec regs_match_file (r0 r1: Regs.t) (rf: reg_file_id) (k: nat{k <= n_regs rf}) : Type0 =
false
null
false
if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Regs.t", "Vale.X64.Machine_s.reg_file_id", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Vale.X64.Machine_s.n_regs", "Prims.op_Equality", "Prims.int", "Prims.l_True", "Prims.bool", "Prims.l_and", "Prims.eq2", "Vale.X64.Machine_s.t_reg", "Vale.X64.Regs.sel", "Vale.X64.QuickCodes.regs_match_file", "Prims.op_Subtraction", "Vale.X64.Machine_s.reg", "Vale.X64.Machine_s.Reg" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val regs_match_file (r0 r1: Regs.t) (rf: reg_file_id) (k: nat{k <= n_regs rf}) : Type0
[ "recursion" ]
Vale.X64.QuickCodes.regs_match_file
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r0: Vale.X64.Regs.t -> r1: Vale.X64.Regs.t -> rf: Vale.X64.Machine_s.reg_file_id -> k: Prims.nat{k <= Vale.X64.Machine_s.n_regs rf} -> Type0
{ "end_col": 70, "end_line": 355, "start_col": 2, "start_line": 352 }
Prims.Tot
val regs_match (r0 r1: Regs.t) (k: nat{k <= n_reg_files}) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec regs_match (r0:Regs.t) (r1:Regs.t) (k:nat{k <= n_reg_files}) : Type0 = if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1)
val regs_match (r0 r1: Regs.t) (k: nat{k <= n_reg_files}) : Type0 let rec regs_match (r0 r1: Regs.t) (k: nat{k <= n_reg_files}) : Type0 =
false
null
false
if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1)
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.Regs.t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Vale.X64.Machine_s.n_reg_files", "Prims.op_Equality", "Prims.int", "Prims.l_True", "Prims.bool", "Prims.l_and", "Vale.X64.QuickCodes.regs_match_file", "Prims.op_Subtraction", "Vale.X64.Machine_s.n_regs", "Vale.X64.QuickCodes.regs_match" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr] let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1) [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val regs_match (r0 r1: Regs.t) (k: nat{k <= n_reg_files}) : Type0
[ "recursion" ]
Vale.X64.QuickCodes.regs_match
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
r0: Vale.X64.Regs.t -> r1: Vale.X64.Regs.t -> k: Prims.nat{k <= Vale.X64.Machine_s.n_reg_files} -> Type0
{ "end_col": 81, "end_line": 360, "start_col": 2, "start_line": 359 }
Prims.Pure
val va_state_match (s0 s1: va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1)
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let va_state_match (s0:va_state) (s1:va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1) = FStar.Classical.move_requires (lemma_state_match s0) s1; state_match s0 s1
val va_state_match (s0 s1: va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1) let va_state_match (s0 s1: va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1) =
false
null
false
FStar.Classical.move_requires (lemma_state_match s0) s1; state_match s0 s1
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[]
[ "Vale.X64.Decls.va_state", "Vale.X64.QuickCodes.state_match", "Prims.unit", "FStar.Classical.move_requires", "Vale.X64.State.state_eq", "Vale.X64.QuickCodes.lemma_state_match", "Prims.l_True", "Prims.l_imp" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr] let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2 [@va_qattr] let wp_If (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k valid_cmp b s0 /\ mods_contains1 mods Mod_flags /\ (let s1 = va_upd_flags havoc_flags s0 in ( eval_cmp s0 b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s1 k) /\ (not (eval_cmp s0 b) ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s1 k)) val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (IfElse (cmp_to_ocmp b) c1 c2) = QProc (IfElse (cmp_to_ocmp b) c1 c2) mods (wp_If b qc1 qc2 mods) (qIf_proof b qc1 qc2 mods) ///// While [@va_qattr] let wp_While_inv (#a #d:Type) (#c:code) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (s1:va_state) (g1:a) (s2:va_state) (g2:a) : Type0 = s2.vs_ok /\ inv s2 g2 /\ mods_contains mods (qc g2).mods /\ dec s2 g2 << dec s1 g1 [@va_qattr] let wp_While_body (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g1:a) (s1:va_state) (k:va_state -> a -> Type0) : Type0 = valid_cmp b s1 /\ (let s1' = va_upd_flags havoc_flags s1 in ( eval_cmp s1 b ==> mods_contains mods (qc g1).mods /\ QProc?.wp (qc g1) s1' (wp_While_inv qc mods inv dec s1 g1)) /\ (not (eval_cmp s1 b) ==> k s1' g1)) [@va_qattr] let wp_While (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = inv s0 g0 /\ mods_contains mods (qc g0).mods /\ mods_contains1 mods Mod_flags /\ // REVIEW: we could get a better WP with forall (...state components...) instead of forall (s1:va_state) (forall (s1:va_state) (g1:a). inv s1 g1 ==> wp_While_body b qc mods inv dec g1 s1 k) val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qWhile (#a #d:Type) (#c:code) (mods:mods_t) (b:cmp) (qc:a -> quickCode a c) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) : quickCode a (While (cmp_to_ocmp b) c) = QProc (While (cmp_to_ocmp b) c) mods (wp_While b qc mods inv dec g0) (qWhile_proof b qc mods inv dec g0) ///// Assert, Assume, AssertBy let tAssertLemma (p:Type0) = unit -> Lemma (requires p) (ensures p) val qAssertLemma (p:Type0) : tAssertLemma p [@va_qattr] let va_qAssert (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg e (fun () -> e) (qAssertLemma e) qcs let tAssumeLemma (p:Type0) = unit -> Lemma (requires True) (ensures p) val qAssumeLemma (p:Type0) : tAssumeLemma p [@va_qattr] let va_qAssume (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg True (fun () -> e) (qAssumeLemma e) qcs let tAssertSquashLemma (p:Type0) = unit -> Ghost (squash p) (requires p) (ensures fun () -> p) val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p [@va_qattr] let va_qAssertSquash (#a:Type) (#cs:codes) (r:range) (msg:string) (e:Type0) (qcs:squash e -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QGhost (squash e) r msg e (fun () -> e) (qAssertSquashLemma e) qcs //let tAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) = // unit -> Lemma (requires t_require s0 /\ wp [] qcs mods (fun _ _ -> p) s0) (ensures p) //val qAssertByLemma (#a:Type) (p:Type0) (qcs:quickCodes a []) (mods:mods_t) (s0:state) : tAssertByLemma p qcs mods s0 // //[@va_qattr] //let va_qAssertBy (#a:Type) (#cs:codes) (mods:mods_t) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (s0:state) (qcsTail:quickCodes a cs) : quickCodes a cs = // QLemma r msg (t_require s0 /\ wp [] qcsBy mods (fun _ _ -> p) s0) (fun () -> p) (qAssertByLemma p qcsBy mods s0) qcsTail [@va_qattr] let va_qAssertBy (#a:Type) (#cs:codes) (r:range) (msg:string) (p:Type0) (qcsBy:quickCodes unit []) (qcsTail:quickCodes a cs) : quickCodes a cs = QAssertBy r msg p qcsBy qcsTail ///// Code val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN) [@va_qattr] let rec regs_match_file (r0:Regs.t) (r1:Regs.t) (rf:reg_file_id) (k:nat{k <= n_regs rf}) : Type0 = if k = 0 then True else let r = Reg rf (k - 1) in Regs.sel r r0 == Regs.sel r r1 /\ regs_match_file r0 r1 rf (k - 1) [@va_qattr] let rec regs_match (r0:Regs.t) (r1:Regs.t) (k:nat{k <= n_reg_files}) : Type0 = if k = 0 then True else regs_match_file r0 r1 (k - 1) (n_regs (k - 1)) /\ regs_match r0 r1 (k - 1) [@va_qattr] let all_regs_match (r0:Regs.t) (r1:Regs.t) : Type0 = regs_match r0 r1 n_reg_files [@va_qattr] let state_match (s0:va_state) (s1:va_state) : Type0 = s0.vs_ok == s1.vs_ok /\ all_regs_match s0.vs_regs s1.vs_regs /\ s0.vs_flags == s1.vs_flags /\ s0.vs_heap == s1.vs_heap /\ s0.vs_stack == s1.vs_stack /\ s0.vs_stackTaint == s1.vs_stackTaint val lemma_state_match (s0:va_state) (s1:va_state) : Lemma (requires state_match s0 s1) (ensures state_eq s0 s1) [@va_qattr] let va_state_match (s0:va_state) (s1:va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1)
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val va_state_match (s0 s1: va_state) : Pure Type0 (requires True) (ensures fun b -> b ==> state_eq s0 s1)
[]
Vale.X64.QuickCodes.va_state_match
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s0: Vale.X64.Decls.va_state -> s1: Vale.X64.Decls.va_state -> Prims.Pure Type0
{ "end_col": 19, "end_line": 385, "start_col": 2, "start_line": 384 }
Prims.Tot
val cmp_to_ocmp (c: cmp) : ocmp
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2
val cmp_to_ocmp (c: cmp) : ocmp let cmp_to_ocmp (c: cmp) : ocmp =
false
null
false
match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.cmp", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "Vale.X64.Decls.va_cmp_eq", "Vale.X64.Decls.va_cmp_ne", "Vale.X64.Decls.va_cmp_le", "Vale.X64.Decls.va_cmp_ge", "Vale.X64.Decls.va_cmp_lt", "Vale.X64.Decls.va_cmp_gt", "Vale.X64.Decls.ocmp" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr]
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val cmp_to_ocmp (c: cmp) : ocmp
[]
Vale.X64.QuickCodes.cmp_to_ocmp
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c: Vale.X64.QuickCodes.cmp -> Vale.X64.Decls.ocmp
{ "end_col": 35, "end_line": 220, "start_col": 2, "start_line": 214 }
Prims.Tot
val valid_cmp (c: cmp) (s: va_state) : Type0
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s
val valid_cmp (c: cmp) (s: va_state) : Type0 let valid_cmp (c: cmp) (s: va_state) : Type0 =
false
null
false
match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "total" ]
[ "Vale.X64.QuickCodes.cmp", "Vale.X64.Decls.va_state", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "Prims.l_and", "Vale.X64.Decls.valid_operand" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr]
false
true
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_cmp (c: cmp) (s: va_state) : Type0
[]
Vale.X64.QuickCodes.valid_cmp
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
c: Vale.X64.QuickCodes.cmp -> s: Vale.X64.Decls.va_state -> Type0
{ "end_col": 60, "end_line": 230, "start_col": 2, "start_line": 224 }
Prims.GTot
val eval_cmp (s: va_state) (c: cmp) : GTot bool
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let eval_cmp (s:va_state) (c:cmp) : GTot bool = match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2
val eval_cmp (s: va_state) (c: cmp) : GTot bool let eval_cmp (s: va_state) (c: cmp) : GTot bool =
false
null
false
match c with | Cmp_eq o1 o2 -> va_eval_opr64 s o1 = va_eval_opr64 s o2 | Cmp_ne o1 o2 -> va_eval_opr64 s o1 <> va_eval_opr64 s o2 | Cmp_le o1 o2 -> va_eval_opr64 s o1 <= va_eval_opr64 s o2 | Cmp_ge o1 o2 -> va_eval_opr64 s o1 >= va_eval_opr64 s o2 | Cmp_lt o1 o2 -> va_eval_opr64 s o1 < va_eval_opr64 s o2 | Cmp_gt o1 o2 -> va_eval_opr64 s o1 > va_eval_opr64 s o2
{ "checked_file": "Vale.X64.QuickCodes.fsti.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.Stack_i.fsti.checked", "Vale.X64.Regs.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.X64.QuickCodes.fsti" }
[ "sometrivial" ]
[ "Vale.X64.Decls.va_state", "Vale.X64.QuickCodes.cmp", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "Prims.op_Equality", "Vale.Def.Types_s.nat64", "Vale.X64.Decls.va_eval_opr64", "Prims.op_disEquality", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Prims.op_GreaterThan", "Prims.bool" ]
[]
module Vale.X64.QuickCodes // Optimized weakest precondition generation for 'quick' procedures open FStar.Mul open FStar.Range open Vale.Def.Prop_s open Vale.Arch.HeapImpl open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.Stack_i open Vale.X64.State open Vale.X64.Decls open Vale.X64.QuickCode unfold let code = va_code unfold let codes = va_codes unfold let fuel = va_fuel unfold let eval = eval_code [@va_qattr "opaque_to_smt"] let labeled_wrap (r:range) (msg:string) (p:Type0) : GTot Type0 = labeled r msg p // REVIEW: when used inside a function definition, 'labeled' can show up in an SMT query // as an uninterpreted function. Make a wrapper around labeled that is interpreted: [@va_qattr "opaque_to_smt"] let label (r:range) (msg:string) (p:Type0) : Ghost Type (requires True) (ensures fun q -> q <==> p) = assert_norm (labeled_wrap r msg p <==> p); labeled_wrap r msg p val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)] // wrap "precedes" and LexCons to avoid issues with label (precedes ...) let precedes_wrap (#a:Type) (x y:a) : GTot Type0 = precedes x y [@va_qattr] let rec mods_contains1 (allowed:mods_t) (found:mod_t) : bool = match allowed with | [] -> mod_eq Mod_None found | h::t -> mod_eq h found || mods_contains1 t found [@va_qattr] let rec mods_contains (allowed:mods_t) (found:mods_t) : bool = match found with | [] -> true | h::t -> mods_contains1 allowed h && mods_contains allowed t [@va_qattr] let if_code (b:bool) (c1:code) (c2:code) : code = if b then c1 else c2 open FStar.Monotonic.Pure noeq type quickCodes (a:Type0) : codes -> Type = | QEmpty: a -> quickCodes a [] | QSeq: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> quickCodes a cs -> quickCodes a (c::cs) | QBind: #b:Type -> #c:code -> #cs:codes -> r:range -> msg:string -> quickCode b c -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a (c::cs) | QGetState: #cs:codes -> (va_state -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QPURE: #cs:codes -> r:range -> msg:string -> pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre} -> (unit -> PURE unit (as_pure_wp pre)) -> quickCodes a cs -> quickCodes a cs //| QBindPURE: #cs:codes -> b:Type -> r:range -> msg:string -> pre:((b -> GTot Type0) -> GTot Type0) -> // (unit -> PURE b pre) -> (va_state -> b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QLemma: #cs:codes -> r:range -> msg:string -> pre:Type0 -> post:(squash pre -> Type0) -> (unit -> Lemma (requires pre) (ensures post ())) -> quickCodes a cs -> quickCodes a cs | QGhost: #cs:codes -> b:Type -> r:range -> msg:string -> pre:Type0 -> post:(b -> Type0) -> (unit -> Ghost b (requires pre) (ensures post)) -> (b -> GTot (quickCodes a cs)) -> quickCodes a ((Block [])::cs) | QAssertBy: #cs:codes -> r:range -> msg:string -> p:Type0 -> quickCodes unit [] -> quickCodes a cs -> quickCodes a cs [@va_qattr] unfold let va_QBind (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a (c::cs) = QBind r msg qc qcs [@va_qattr] unfold let va_QEmpty (#a:Type0) (v:a) : quickCodes a [] = QEmpty v [@va_qattr] unfold let va_QLemma (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:Type0) (post:(squash pre -> Type0)) (l:unit -> Lemma (requires pre) (ensures post ())) (qcs:quickCodes a cs) : quickCodes a cs = QLemma r msg pre post l qcs [@va_qattr] unfold let va_QSeq (#a:Type0) (#b:Type) (#c:code) (#cs:codes) (r:range) (msg:string) (qc:quickCode b c) (qcs:quickCodes a cs) : quickCodes a (c::cs) = QSeq r msg qc qcs [@va_qattr] let va_qPURE (#cs:codes) (#pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (#a:Type0) (r:range) (msg:string) ($l:unit -> PURE unit (intro_pure_wp_monotonicity pre; pre)) (qcs:quickCodes a cs) : quickCodes a cs = QPURE r msg pre l qcs (* REVIEW: this might be useful, but inference of pre doesn't work as well as for va_qPURE (need to provide pre explicitly; as a result, no need to put $ on l) [@va_qattr] let va_qBindPURE (#a #b:Type0) (#cs:codes) (pre:(b -> GTot Type0) -> GTot Type0) (r:range) (msg:string) (l:unit -> PURE b pre) (qcs:va_state -> b -> GTot (quickCodes a cs)) : quickCodes a ((Block [])::cs) = QBindPURE b r msg pre l qcs *) [@va_qattr] let wp_proc (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = match qc with | QProc _ _ wp _ -> wp s0 k let wp_Seq_t (a:Type0) = va_state -> a -> Type0 let wp_Bind_t (a:Type0) = va_state -> a -> Type0 let k_AssertBy (p:Type0) (_:va_state) () = p [@va_qattr] let va_range1 = mk_range "" 0 0 0 0 val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x) [@va_qattr] let rec wp (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Tot Type0 (decreases %[cs; 0; qcs]) = match qcs with | QEmpty g -> k s0 g | QSeq r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Seq cs qcs mods k)) | QBind r msg qc qcs -> let c::cs = cs in label r msg (mods_contains mods qc.mods /\ wp_proc c qc s0 (wp_Bind cs qcs mods k)) | QGetState f -> let c::cs = cs in wp cs (f s0) mods k s0 | QPURE r msg pre l qcs -> // REVIEW: rather than just applying 'pre' directly to k, // we define this in a roundabout way so that: // - it works even if 'pre' isn't known to be monotonic // - F*'s error reporting uses 'guard_free' to process labels inside (wp cs qcs mods k s0) (forall (p:unit -> GTot Type0).//{:pattern (pre p)} (forall (u:unit).{:pattern (guard_free (p u))} wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p)) (* | QBindPURE b r msg pre l qcs -> let c::cs = cs in (forall (p:b -> GTot Type0).//{:pattern (pre p)} (forall (g:b).{:pattern (guard_free (p g))} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p)) *) | QLemma r msg pre post l qcs -> label r msg pre /\ (post () ==> wp cs qcs mods k s0) | QGhost b r msg pre post l qcs -> let c::cs = cs in label r msg pre /\ (forall (g:b). post g ==> wp cs (qcs g) mods k s0) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; wp [] qcsBy mods (k_AssertBy p) s0 /\ (p ==> wp cs qcs mods k s0) // Hoist lambdas out of main definition to avoid issues with function equality and wp_Seq (#a:Type0) (#b:Type0) (cs:codes) (qcs:quickCodes b cs) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Seq_t a) (decreases %[cs; 1; qcs]) = let f s0 _ = wp cs qcs mods k s0 in f and wp_Bind (#a:Type0) (#b:Type0) (cs:codes) (qcs:va_state -> a -> GTot (quickCodes b cs)) (mods:mods_t) (k:va_state -> b -> Type0) : Tot (wp_Bind_t a) (decreases %[cs; 1; qcs]) = let f s0 g = wp cs (qcs s0 g) mods k s0 in f val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN ) ///// Block unfold let block = va_Block [@va_qattr] let wp_block (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = wp cs (qcs s0) mods k s0 val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let qblock (#a:Type) (#cs:codes) (mods:mods_t) (qcs:va_state -> GTot (quickCodes a cs)) : quickCode a (block cs) = QProc (block cs) mods (wp_block qcs mods) (qblock_proof qcs mods) ///// If, InlineIf [@va_qattr] let wp_InlineIf (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Type0 = // REVIEW: this duplicates k ( b ==> mods_contains mods qc1.mods /\ QProc?.wp qc1 s0 k) /\ (not b ==> mods_contains mods qc2.mods /\ QProc?.wp qc2 s0 k) val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g ) [@"opaque_to_smt" va_qattr] let va_qInlineIf (#a:Type) (#c1:code) (#c2:code) (mods:mods_t) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) : quickCode a (if_code b c1 c2) = QProc (if_code b c1 c2) mods (wp_InlineIf b qc1 qc2 mods) (qInlineIf_proof b qc1 qc2 mods) noeq type cmp = | Cmp_eq : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ne : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_le : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_ge : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_lt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp | Cmp_gt : o1:operand64{not (OMem? o1 || OStack? o1)} -> o2:operand64{not (OMem? o2 || OStack? o2)} -> cmp [@va_qattr] let cmp_to_ocmp (c:cmp) : ocmp = match c with | Cmp_eq o1 o2 -> va_cmp_eq o1 o2 | Cmp_ne o1 o2 -> va_cmp_ne o1 o2 | Cmp_le o1 o2 -> va_cmp_le o1 o2 | Cmp_ge o1 o2 -> va_cmp_ge o1 o2 | Cmp_lt o1 o2 -> va_cmp_lt o1 o2 | Cmp_gt o1 o2 -> va_cmp_gt o1 o2 [@va_qattr] let valid_cmp (c:cmp) (s:va_state) : Type0 = match c with | Cmp_eq o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ne o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_le o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_ge o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_lt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s | Cmp_gt o1 o2 -> valid_operand o1 s /\ valid_operand o2 s [@va_qattr]
false
false
Vale.X64.QuickCodes.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eval_cmp (s: va_state) (c: cmp) : GTot bool
[]
Vale.X64.QuickCodes.eval_cmp
{ "file_name": "vale/code/arch/x64/Vale.X64.QuickCodes.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: Vale.X64.Decls.va_state -> c: Vale.X64.QuickCodes.cmp -> Prims.GTot Prims.bool
{ "end_col": 60, "end_line": 240, "start_col": 2, "start_line": 234 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let uint64 = UInt64.t
let uint64 =
false
null
false
UInt64.t
{ "checked_file": "Vale.Stdcalls.X64.GCTR.fst.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ "total" ]
[ "FStar.UInt64.t" ]
[]
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR
false
true
Vale.Stdcalls.X64.GCTR.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val uint64 : Prims.eqtype
[]
Vale.Stdcalls.X64.GCTR.uint64
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.eqtype
{ "end_col": 21, "end_line": 27, "start_col": 13, "start_line": 27 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
let t128_mod =
false
null
false
TD_Buffer TUInt8 TUInt128 default_bq
{ "checked_file": "Vale.Stdcalls.X64.GCTR.fst.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ "total" ]
[ "Vale.Interop.Base.TD_Buffer", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "Vale.Interop.Base.default_bq" ]
[]
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x [@__reduce__] noextract let b128 = buf_t TUInt8 TUInt128
false
true
Vale.Stdcalls.X64.GCTR.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val t128_mod : Vale.Interop.Base.td
[]
Vale.Stdcalls.X64.GCTR.t128_mod
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Vale.Interop.Base.td
{ "end_col": 51, "end_line": 38, "start_col": 15, "start_line": 38 }
Prims.Tot
[ { "abbrev": true, "full_module": "Vale.AES.X64.GCTR", "short_module": "GC" }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.X64.Machine_s", "short_module": "MS" }, { "abbrev": true, "full_module": "Vale.X64.State", "short_module": "VS" }, { "abbrev": false, "full_module": "Vale.X64.MemoryAdapters", "short_module": null }, { "abbrev": true, "full_module": "Vale.AsLowStar.Wrapper", "short_module": "W" }, { "abbrev": true, "full_module": "Vale.Interop.Assumptions", "short_module": "IA" }, { "abbrev": true, "full_module": "Vale.X64.Decls", "short_module": "V" }, { "abbrev": true, "full_module": "Vale.X64.Memory", "short_module": "ME" }, { "abbrev": true, "full_module": "Vale.AsLowStar.LowStarSig", "short_module": "LSig" }, { "abbrev": true, "full_module": "Vale.AsLowStar.ValeSig", "short_module": "VSig" }, { "abbrev": true, "full_module": "Vale.Interop.X64", "short_module": "IX64" }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Stdcalls.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let b128 = buf_t TUInt8 TUInt128
let b128 =
false
null
false
buf_t TUInt8 TUInt128
{ "checked_file": "Vale.Stdcalls.X64.GCTR.fst.checked", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.MemoryAdapters.fsti.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Decls.fsti.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "Vale.Interop.Assumptions.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCTR.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCTR.fst" }
[ "total" ]
[ "Vale.Interop.Base.buf_t", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128" ]
[]
module Vale.Stdcalls.X64.GCTR open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Types_s open Vale.Interop.Base module IX64 = Vale.Interop.X64 module VSig = Vale.AsLowStar.ValeSig module LSig = Vale.AsLowStar.LowStarSig module ME = Vale.X64.Memory module V = Vale.X64.Decls module IA = Vale.Interop.Assumptions module W = Vale.AsLowStar.Wrapper open Vale.X64.MemoryAdapters module VS = Vale.X64.State module MS = Vale.X64.Machine_s open Vale.AES.AES_s module GC = Vale.AES.X64.GCTR let uint64 = UInt64.t (* A little utility to trigger normalization in types *) noextract let as_t (#a:Type) (x:normal a) : a = x noextract let as_normal_t (#a:Type) (x:a) : normal a = x
false
true
Vale.Stdcalls.X64.GCTR.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val b128 : Type0
[]
Vale.Stdcalls.X64.GCTR.b128
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCTR.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 32, "end_line": 36, "start_col": 11, "start_line": 36 }