file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.UInt.fst | FStar.UInt.from_vec_aux | val from_vec_aux: #n:nat -> a:bv_t n -> s1:nat{s1 < n} -> s2:nat{s2 < s1} ->
Lemma (requires True)
(ensures (from_vec #s2 (slice a 0 s2)) * pow2 (n - s2) + (from_vec #(s1 - s2) (slice a s2 s1)) * pow2 (n - s1) + (from_vec #(n - s1) (slice a s1 n)) = ((from_vec #s2 (slice a 0 s2)) * pow2 (s1 - s2) + (from_vec #(s1 - s2) (slice a s2 s1))) * pow2 (n - s1) + (from_vec #(n - s1) (slice a s1 n))) | val from_vec_aux: #n:nat -> a:bv_t n -> s1:nat{s1 < n} -> s2:nat{s2 < s1} ->
Lemma (requires True)
(ensures (from_vec #s2 (slice a 0 s2)) * pow2 (n - s2) + (from_vec #(s1 - s2) (slice a s2 s1)) * pow2 (n - s1) + (from_vec #(n - s1) (slice a s1 n)) = ((from_vec #s2 (slice a 0 s2)) * pow2 (s1 - s2) + (from_vec #(s1 - s2) (slice a s2 s1))) * pow2 (n - s1) + (from_vec #(n - s1) (slice a s1 n))) | let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 94,
"start_col": 0,
"start_line": 91
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"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"
} | false | a: FStar.BitVector.bv_t n -> s1: Prims.nat{s1 < n} -> s2: Prims.nat{s2 < s1}
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.from_vec (FStar.Seq.Base.slice a 0 s2) * Prims.pow2 (n - s2) +
FStar.UInt.from_vec (FStar.Seq.Base.slice a s2 s1) * Prims.pow2 (n - s1) +
FStar.UInt.from_vec (FStar.Seq.Base.slice a s1 n) =
(FStar.UInt.from_vec (FStar.Seq.Base.slice a 0 s2) * Prims.pow2 (s1 - s2) +
FStar.UInt.from_vec (FStar.Seq.Base.slice a s2 s1)) *
Prims.pow2 (n - s1) +
FStar.UInt.from_vec (FStar.Seq.Base.slice a s1 n)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.BitVector.bv_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Math.Lemmas.pow2_plus",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.UInt.from_vec",
"FStar.Seq.Base.slice",
"Prims.bool",
"Prims.pow2",
"FStar.Math.Lemmas.paren_mul_left"
] | [] | true | false | true | false | false | let from_vec_aux #n a s1 s2 =
| paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1) | false |
FStar.UInt.fst | FStar.UInt.inverse_aux | val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} ->
Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i)
[SMTPat (index (to_vec (from_vec vec)) i)] | val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} ->
Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i)
[SMTPat (index (to_vec (from_vec vec)) i)] | let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 80,
"start_col": 0,
"start_line": 77
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | vec: FStar.BitVector.bv_t n -> i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index vec i =
FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.from_vec vec)) i)
[SMTPat (FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.from_vec vec)) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.BitVector.bv_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims._assert",
"Prims.op_Modulus",
"FStar.UInt.from_vec",
"FStar.Seq.Base.index",
"Prims.bool",
"FStar.UInt.inverse_aux",
"FStar.Seq.Base.slice",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec inverse_aux #n vec i =
| if i = n - 1
then assert ((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i | false |
FStar.UInt.fst | FStar.UInt.append_lemma | val append_lemma: #n:pos -> #m:pos -> a:bv_t n -> b:bv_t m ->
Lemma (from_vec #(n + m) (append a b) = (from_vec #n a) * pow2 m + (from_vec #m b)) | val append_lemma: #n:pos -> #m:pos -> a:bv_t n -> b:bv_t m ->
Lemma (from_vec #(n + m) (append a b) = (from_vec #n a) * pow2 m + (from_vec #m b)) | let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 116,
"start_col": 0,
"start_line": 113
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.BitVector.bv_t n -> b: FStar.BitVector.bv_t m
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.from_vec (FStar.Seq.Base.append a b) =
FStar.UInt.from_vec a * Prims.pow2 m + FStar.UInt.from_vec b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.BitVector.bv_t",
"FStar.UInt.from_vec_propriety",
"Prims.op_Addition",
"FStar.Seq.Base.append",
"Prims.bool",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice"
] | [] | true | false | true | false | false | let append_lemma #n #m a b =
| assert (equal a (slice (append a b) 0 n));
assert (equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n | false |
FStar.UInt.fst | FStar.UInt.one_to_vec_lemma | val one_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i)
[SMTPat (index (to_vec (one n)) i)] | val one_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i)
[SMTPat (index (to_vec (one n)) i)] | let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 134,
"start_col": 0,
"start_line": 133
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.one n)) i =
FStar.Seq.Base.index (FStar.BitVector.elem_vec (n - 1)) i)
[SMTPat (FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.one n)) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.bool",
"FStar.UInt.zero_to_vec_lemma",
"Prims.unit"
] | [] | false | false | true | false | false | let one_to_vec_lemma #n i =
| if i = n - 1 then () else zero_to_vec_lemma #n i | false |
Steel.ST.Array.fst | Steel.ST.Array.ghost_split | val ghost_split
(#opened: _)
(#elt: Type)
(#x: Seq.seq elt)
(#p: P.perm)
(a: array elt)
(i: US.t)
: STGhost (squash (US.v i <= length a /\ US.v i <= Seq.length x)) opened
(pts_to a p x)
(fun res ->
pts_to (split_l a i) p (Seq.slice x 0 (US.v i)) `star`
pts_to (split_r a i) p (Seq.slice x (US.v i) (Seq.length x)))
(US.v i <= length a)
(fun res ->
x == Seq.append (Seq.slice x 0 (US.v i)) (Seq.slice x (US.v i) (Seq.length x))
) | val ghost_split
(#opened: _)
(#elt: Type)
(#x: Seq.seq elt)
(#p: P.perm)
(a: array elt)
(i: US.t)
: STGhost (squash (US.v i <= length a /\ US.v i <= Seq.length x)) opened
(pts_to a p x)
(fun res ->
pts_to (split_l a i) p (Seq.slice x 0 (US.v i)) `star`
pts_to (split_r a i) p (Seq.slice x (US.v i) (Seq.length x)))
(US.v i <= length a)
(fun res ->
x == Seq.append (Seq.slice x 0 (US.v i)) (Seq.slice x (US.v i) (Seq.length x))
) | let ghost_split
#_ #_ #x #p a i
=
rewrite
(pts_to a _ _)
(H.pts_to a p (seq_map raise x));
let _ = H.ghost_split a i in
//H.ghost_split a i;
assert (seq_map raise (Seq.slice x 0 (US.v i)) `Seq.equal` Seq.slice (seq_map raise x) 0 (US.v i));
rewrite
(H.pts_to (H.split_l a i) _ _)
(H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i))));
rewrite
(H.pts_to (split_l a i) _ _)
(pts_to (split_l a i) _ _);
assert (seq_map raise (Seq.slice x (US.v i) (Seq.length x)) `Seq.equal` Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x)));
Seq.lemma_split x (US.v i);
rewrite
(H.pts_to (H.split_r a i) _ _)
(H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x))));
rewrite
(H.pts_to (split_r a i) _ _)
(pts_to (split_r a i) _ _) | {
"file_name": "lib/steel/Steel.ST.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 228,
"start_col": 0,
"start_line": 206
} | (*
Copyright 2020, 2021, 2022 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 Steel.ST.Array
module US = FStar.SizeT
/// Lifting a value of universe 0 to universe 1. We use
/// FStar.Universe, since FStar.Extraction.Krml is set to extract
/// those functions to identity.
inline_for_extraction
[@@ noextract_to "krml"]
let raise_t (t: Type0) : Type u#1 = FStar.Universe.raise_t t
inline_for_extraction
[@@noextract_to "krml"]
let raise (#t: Type) (x: t) : Tot (raise_t t) =
FStar.Universe.raise_val x
inline_for_extraction
[@@noextract_to "krml"]
let lower (#t: Type) (x: raise_t t) : Tot t =
FStar.Universe.downgrade_val x
/// A map operation on sequences. Here we only need Ghost versions,
/// because such sequences are only used in vprops or with their
/// selectors.
let rec seq_map
(#t: Type u#a)
(#t' : Type u#b)
(f: (t -> GTot t'))
(s: Seq.seq t)
: Ghost (Seq.seq t')
(requires True)
(ensures (fun s' ->
Seq.length s' == Seq.length s /\
(forall i . {:pattern (Seq.index s' i)} Seq.index s' i == f (Seq.index s i))
))
(decreases (Seq.length s))
= if Seq.length s = 0
then Seq.empty
else Seq.cons (f (Seq.index s 0)) (seq_map f (Seq.slice s 1 (Seq.length s)))
let seq_map_append
(#t: Type u#a)
(#t': Type u#b)
(f: (t -> GTot t'))
(s1 s2: Seq.seq t)
: Lemma
(seq_map f (s1 `Seq.append` s2) `Seq.equal` (seq_map f s1 `Seq.append` seq_map f s2))
= ()
let seq_map_raise_inj
(#elt: Type0)
(s1 s2: Seq.seq elt)
: Lemma
(requires (seq_map raise s1 == seq_map raise s2))
(ensures (s1 == s2))
[SMTPat (seq_map raise s1); SMTPat (seq_map raise s2)]
= assert (seq_map lower (seq_map raise s1) `Seq.equal` s1);
assert (seq_map lower (seq_map raise s2) `Seq.equal` s2)
/// Implementation of the interface
/// base, ptr, array, pts_to
module H = Steel.ST.HigherArray
let base_t elt = H.base_t (raise_t elt)
let base_len b = H.base_len b
let ptr elt = H.ptr (raise_t elt)
let null_ptr elt = H.null_ptr (raise_t elt)
let is_null_ptr p = H.is_null_ptr p
let base p = H.base p
let offset p = H.offset p
let ptr_base_offset_inj p1 p2 = H.ptr_base_offset_inj p1 p2
let base_len_null_ptr elt = H.base_len_null_ptr (raise_t elt)
let length_fits a = H.length_fits a
let pts_to a p s = H.pts_to a p (seq_map raise s)
let pts_to_length a s =
H.pts_to_length a _
let h_array_eq'
(#t: Type u#1)
(a1 a2: H.array t)
: Lemma
(requires (
dfst a1 == dfst a2 /\
(Ghost.reveal (dsnd a1) <: nat) == Ghost.reveal (dsnd a2)
))
(ensures (
a1 == a2
))
= ()
let pts_to_not_null #_ #t #p a s =
let _ = H.pts_to_not_null #_ #_ #p a (seq_map raise s) in
assert (a =!= H.null #(raise_t t));
Classical.move_requires (h_array_eq' a) (H.null #(raise_t t));
noop ()
let pts_to_inj a p1 s1 p2 s2 =
H.pts_to_inj a p1 (seq_map raise s1) p2 (seq_map raise s2)
/// Non-selector operations.
let malloc x n =
let res = H.malloc (raise x) n in
assert (seq_map raise (Seq.create (US.v n) x) `Seq.equal` Seq.create (US.v n) (raise x));
rewrite
(H.pts_to res _ _)
(pts_to res _ _);
return res
let free #_ x =
let s = elim_exists () in
rewrite
(pts_to x _ _)
(H.pts_to x P.full_perm (seq_map raise s));
H.free x
let share
#_ #_ #x a p p1 p2
= rewrite
(pts_to a _ _)
(H.pts_to a p (seq_map raise x));
H.share a p p1 p2;
rewrite
(H.pts_to a p1 _)
(pts_to a p1 x);
rewrite
(H.pts_to a p2 _)
(pts_to a p2 x)
let gather
#_ #_ a #x1 p1 #x2 p2
= rewrite
(pts_to a p1 _)
(H.pts_to a p1 (seq_map raise x1));
rewrite
(pts_to a p2 _)
(H.pts_to a p2 (seq_map raise x2));
H.gather a p1 p2;
rewrite
(H.pts_to a _ _)
(pts_to _ _ _)
let index #_ #p a #s i =
rewrite
(pts_to a _ _)
(H.pts_to a p (seq_map raise s));
let res = H.index a i in
rewrite
(H.pts_to _ _ _)
(pts_to _ _ _);
return (lower res)
let upd #_ a #s i v =
rewrite
(pts_to a _ _)
(H.pts_to a P.full_perm (seq_map raise s));
H.upd a i (raise v);
assert (seq_map raise (Seq.upd s (US.v i) v) `Seq.equal` Seq.upd (seq_map raise s) (US.v i) (raise v));
rewrite
(H.pts_to _ _ _)
(pts_to _ _ _)
let ghost_join
#_ #_ #x1 #x2 #p a1 a2 h
= rewrite
(pts_to a1 _ _)
(H.pts_to a1 p (seq_map raise x1));
rewrite
(pts_to a2 _ _)
(H.pts_to a2 p (seq_map raise x2));
H.ghost_join a1 a2 h;
assert (seq_map raise (x1 `Seq.append` x2) `Seq.equal` (seq_map raise x1 `Seq.append` seq_map raise x2));
rewrite
(H.pts_to _ _ _)
(H.pts_to (merge a1 a2) p (seq_map raise (x1 `Seq.append` x2)));
rewrite
(H.pts_to _ _ _)
(pts_to (merge a1 a2) _ _)
let ptr_shift p off = H.ptr_shift p off | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.HigherArray.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.HigherArray",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: Steel.ST.Array.array elt -> i: FStar.SizeT.t
-> Steel.ST.Effect.Ghost.STGhost
(Prims.squash (FStar.SizeT.v i <= Steel.ST.Array.length a /\
FStar.SizeT.v i <= FStar.Seq.Base.length x)) | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"FStar.Seq.Base.seq",
"Steel.FractionalPermission.perm",
"Steel.ST.Array.array",
"FStar.SizeT.t",
"Steel.ST.Util.rewrite",
"Steel.ST.HigherArray.pts_to",
"Steel.ST.Array.raise_t",
"Steel.ST.Array.split_r",
"Steel.ST.Array.seq_map",
"Steel.ST.Array.raise",
"FStar.Seq.Base.slice",
"FStar.SizeT.v",
"FStar.Seq.Base.length",
"Steel.ST.Array.pts_to",
"Prims.unit",
"Steel.ST.HigherArray.split_r",
"Prims.squash",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Steel.ST.Array.length",
"FStar.Seq.Properties.lemma_split",
"Prims._assert",
"FStar.Seq.Base.equal",
"Steel.ST.Array.split_l",
"FStar.Ghost.hide",
"Steel.ST.HigherArray.split_l",
"Steel.ST.HigherArray.length",
"Steel.ST.HigherArray.ghost_split"
] | [] | false | true | true | false | false | let ghost_split #_ #_ #x #p a i =
| rewrite (pts_to a _ _) (H.pts_to a p (seq_map raise x));
let _ = H.ghost_split a i in
assert ((seq_map raise (Seq.slice x 0 (US.v i)))
`Seq.equal`
(Seq.slice (seq_map raise x) 0 (US.v i)));
rewrite (H.pts_to (H.split_l a i) _ _)
(H.pts_to (split_l a i) p (seq_map raise (Seq.slice x 0 (US.v i))));
rewrite (H.pts_to (split_l a i) _ _) (pts_to (split_l a i) _ _);
assert ((seq_map raise (Seq.slice x (US.v i) (Seq.length x)))
`Seq.equal`
(Seq.slice (seq_map raise x) (US.v i) (Seq.length (seq_map raise x))));
Seq.lemma_split x (US.v i);
rewrite (H.pts_to (H.split_r a i) _ _)
(H.pts_to (split_r a i) p (seq_map raise (Seq.slice x (US.v i) (Seq.length x))));
rewrite (H.pts_to (split_r a i) _ _) (pts_to (split_r a i) _ _) | false |
FStar.UInt.fst | FStar.UInt.slice_right_lemma | val slice_right_lemma: #n:pos -> a:bv_t n -> s:pos{s < n} ->
Lemma (requires True)
(ensures from_vec #s (slice a (n - s) n) = (from_vec #n a) % (pow2 s)) | val slice_right_lemma: #n:pos -> a:bv_t n -> s:pos{s < n} ->
Lemma (requires True)
(ensures from_vec #s (slice a (n - s) n) = (from_vec #n a) % (pow2 s)) | let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 126,
"start_col": 0,
"start_line": 123
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.BitVector.bv_t n -> s: Prims.pos{s < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.from_vec (FStar.Seq.Base.slice a (n - s) n) = FStar.UInt.from_vec a % Prims.pow2 s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.BitVector.bv_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Math.Lemmas.small_modulo_lemma_1",
"FStar.UInt.from_vec",
"FStar.Seq.Base.slice",
"Prims.bool",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.unit",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.UInt.from_vec_propriety"
] | [] | true | false | true | false | false | let slice_right_lemma #n a s =
| from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n))
(pow2 s)
(from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s) | false |
FStar.UInt.fst | FStar.UInt.zero_from_vec_lemma | val zero_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n)
[SMTPat (from_vec (zero_vec #n))] | val zero_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n)
[SMTPat (from_vec (zero_vec #n))] | let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 77,
"end_line": 131,
"start_col": 0,
"start_line": 131
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | FStar.Pervasives.Lemma (ensures FStar.UInt.from_vec FStar.BitVector.zero_vec = FStar.UInt.zero n)
[SMTPat (FStar.UInt.from_vec FStar.BitVector.zero_vec)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.to_vec_lemma_2",
"FStar.UInt.from_vec",
"FStar.BitVector.zero_vec",
"FStar.UInt.zero",
"Prims.unit"
] | [] | true | false | true | false | false | let zero_from_vec_lemma #n =
| to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n) | false |
FStar.UInt.fst | FStar.UInt.zero_to_vec_lemma | val zero_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i)
[SMTPat (index (to_vec (zero n)) i)] | val zero_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i)
[SMTPat (index (to_vec (zero n)) i)] | let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 129,
"start_col": 0,
"start_line": 128
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.zero n)) i =
FStar.Seq.Base.index FStar.BitVector.zero_vec i)
[SMTPat (FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.zero n)) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.bool",
"FStar.UInt.zero_to_vec_lemma",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec zero_to_vec_lemma #n i =
| if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i | false |
FStar.UInt.fst | FStar.UInt.slice_left_lemma | val slice_left_lemma: #n:pos -> a:bv_t n -> s:pos{s < n} ->
Lemma (requires True)
(ensures from_vec #s (slice a 0 s) = (from_vec #n a) / (pow2 (n - s))) | val slice_left_lemma: #n:pos -> a:bv_t n -> s:pos{s < n} ->
Lemma (requires True)
(ensures from_vec #s (slice a 0 s) = (from_vec #n a) / (pow2 (n - s))) | let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 73,
"end_line": 121,
"start_col": 0,
"start_line": 118
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.BitVector.bv_t n -> s: Prims.pos{s < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.from_vec (FStar.Seq.Base.slice a 0 s) = FStar.UInt.from_vec a / Prims.pow2 (n - s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.BitVector.bv_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Math.Lemmas.small_division_lemma_1",
"FStar.UInt.from_vec",
"Prims.op_Subtraction",
"FStar.Seq.Base.slice",
"Prims.bool",
"Prims.pow2",
"Prims.unit",
"FStar.Math.Lemmas.division_addition_lemma",
"FStar.UInt.from_vec_propriety"
] | [] | true | false | true | false | false | let slice_left_lemma #n a s =
| from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) | false |
FStar.UInt.fst | FStar.UInt.pow2_to_vec_lemma | val pow2_to_vec_lemma: #n:pos -> p:nat{p < n} -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i)
[SMTPat (index (to_vec (pow2_n #n p)) i)] | val pow2_to_vec_lemma: #n:pos -> p:nat{p < n} -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i)
[SMTPat (index (to_vec (pow2_n #n p)) i)] | let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 139,
"start_col": 0,
"start_line": 136
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | p: Prims.nat{p < n} -> i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.pow2_n p)) i =
FStar.Seq.Base.index (FStar.BitVector.elem_vec (n - p - 1)) i)
[SMTPat (FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.pow2_n p)) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.bool",
"FStar.UInt.one_to_vec_lemma",
"FStar.UInt.pow2_to_vec_lemma",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec pow2_to_vec_lemma #n p i =
| if i = n - 1
then ()
else if p = 0 then one_to_vec_lemma #n i else pow2_to_vec_lemma #(n - 1) (p - 1) i | false |
FStar.UInt.fst | FStar.UInt.pow2_from_vec_lemma | val pow2_from_vec_lemma: #n:pos -> p:nat{p < n} ->
Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1))
[SMTPat (from_vec (elem_vec #n p))] | val pow2_from_vec_lemma: #n:pos -> p:nat{p < n} ->
Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1))
[SMTPat (from_vec (elem_vec #n p))] | let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 67,
"end_line": 142,
"start_col": 0,
"start_line": 141
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | p: Prims.nat{p < n}
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.from_vec (FStar.BitVector.elem_vec p) = FStar.UInt.pow2_n (n - p - 1))
[SMTPat (FStar.UInt.from_vec (FStar.BitVector.elem_vec p))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt.to_vec_lemma_2",
"FStar.UInt.from_vec",
"FStar.BitVector.elem_vec",
"FStar.UInt.pow2_n",
"Prims.op_Subtraction",
"Prims.unit"
] | [] | true | false | true | false | false | let pow2_from_vec_lemma #n p =
| to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1)) | false |
FStar.UInt.fst | FStar.UInt.nth_lemma | val nth_lemma: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires forall (i:nat{i < n}). nth a i = nth b i)
(ensures a = b) | val nth_lemma: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires forall (i:nat{i < n}). nth a i = nth b i)
(ensures a = b) | let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 152,
"start_col": 0,
"start_line": 150
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(requires forall (i: Prims.nat{i < n}). FStar.UInt.nth a i = FStar.UInt.nth b i)
(ensures a = b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.to_vec_lemma_2",
"Prims.unit",
"Prims._assert",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.bool",
"FStar.Seq.Base.index",
"FStar.UInt.to_vec"
] | [] | false | false | true | false | false | let nth_lemma #n a b =
| assert (forall (i: nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b | false |
FStar.UInt.fst | FStar.UInt.ones_from_vec_lemma | val ones_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n)
[SMTPat (from_vec (ones_vec #n))] | val ones_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n)
[SMTPat (from_vec (ones_vec #n))] | let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 148,
"start_col": 0,
"start_line": 147
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | FStar.Pervasives.Lemma (ensures FStar.UInt.from_vec FStar.BitVector.ones_vec = FStar.UInt.ones n)
[SMTPat (FStar.UInt.from_vec FStar.BitVector.ones_vec)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.to_vec_lemma_2",
"FStar.UInt.from_vec",
"FStar.BitVector.ones_vec",
"FStar.UInt.ones",
"Prims.unit"
] | [] | true | false | true | false | false | let ones_from_vec_lemma #n =
| to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n) | false |
FStar.UInt.fst | FStar.UInt.ones_to_vec_lemma | val ones_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (ones n)) i = index (ones_vec #n) i)
[SMTPat (index (to_vec (ones n)) i)] | val ones_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (ones n)) i = index (ones_vec #n) i)
[SMTPat (index (to_vec (ones n)) i)] | let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 145,
"start_col": 0,
"start_line": 144
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.ones n)) i =
FStar.Seq.Base.index FStar.BitVector.ones_vec i)
[SMTPat (FStar.Seq.Base.index (FStar.UInt.to_vec (FStar.UInt.ones n)) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.bool",
"FStar.UInt.ones_to_vec_lemma",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec ones_to_vec_lemma #n i =
| if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i | false |
FStar.UInt.fst | FStar.UInt.from_vec_propriety | val from_vec_propriety: #n:pos -> a:bv_t n -> s:nat{s < n} ->
Lemma (requires True)
(ensures from_vec a = (from_vec #s (slice a 0 s)) * pow2 (n - s) + from_vec #(n - s) (slice a s n))
(decreases (n - s)) | val from_vec_propriety: #n:pos -> a:bv_t n -> s:nat{s < n} ->
Lemma (requires True)
(ensures from_vec a = (from_vec #s (slice a 0 s)) * pow2 (n - s) + from_vec #(n - s) (slice a s n))
(decreases (n - s)) | let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 110,
"start_col": 0,
"start_line": 100
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 2,
"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"
} | false | a: FStar.BitVector.bv_t n -> s: Prims.nat{s < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.from_vec a =
FStar.UInt.from_vec (FStar.Seq.Base.slice a 0 s) * Prims.pow2 (n - s) +
FStar.UInt.from_vec (FStar.Seq.Base.slice a s n)) (decreases n - s) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"FStar.BitVector.bv_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.bool",
"FStar.UInt.seq_slice_lemma",
"Prims.unit",
"FStar.UInt.from_vec_propriety",
"FStar.Seq.Base.slice",
"FStar.UInt.from_vec_aux",
"Prims.op_Addition"
] | [
"recursion"
] | false | false | true | false | false | let rec from_vec_propriety #n a s =
| if s = n - 1
then ()
else
(from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)) | false |
Steel.ST.SeqMatch.fst | Steel.ST.SeqMatch.seq_list_match_nil | val seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> v': t'{v' << v} -> vprop))
: STGhost unit
opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\ Nil? v)
(fun _ -> True) | val seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> v': t'{v' << v} -> vprop))
: STGhost unit
opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\ Nil? v)
(fun _ -> True) | let seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhost unit opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\
Nil? v)
(fun _ -> True)
= noop ();
rewrite
(seq_list_match_nil0 c)
(seq_list_match c v item_match) | {
"file_name": "lib/steel/Steel.ST.SeqMatch.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 35,
"end_line": 78,
"start_col": 0,
"start_line": 63
} | module Steel.ST.SeqMatch
include Steel.ST.OnRange
open Steel.ST.GenElim
module Seq = FStar.Seq
module SZ = FStar.SizeT
(* `seq_list_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a list of high-level
values. `seq_list_match` is carefully designed to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values. *)
[@@__reduce__]
let seq_list_match_nil0
(#t: Type)
(c: Seq.seq t)
: Tot vprop
= pure (c `Seq.equal` Seq.empty)
[@@__reduce__]
let seq_list_match_cons0
(#t #t': Type)
(c: Seq.seq t)
(l: list t' { Cons? l })
(item_match: (t -> (v': t' { v' << l }) -> vprop))
(seq_list_match: (Seq.seq t -> (v': list t') -> (raw_data_item_match: (t -> (v'': t' { v'' << v' }) -> vprop) { v' << l }) ->
vprop))
: Tot vprop
= exists_ (fun (c1: t) -> exists_ (fun (c2: Seq.seq t) ->
item_match c1 (List.Tot.hd l) `star`
seq_list_match c2 (List.Tot.tl l) item_match `star`
pure (c `Seq.equal` Seq.cons c1 c2)
))
let rec seq_list_match
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Tot vprop
(decreases v)
= if Nil? v
then seq_list_match_nil0 c
else seq_list_match_cons0 c v item_match seq_list_match
let seq_list_match_cons_eq
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Lemma
(requires (Cons? v))
(ensures (
seq_list_match c v item_match ==
seq_list_match_cons0 c v item_match seq_list_match
))
= let a :: q = v in
assert_norm (seq_list_match c (a :: q) item_match ==
seq_list_match_cons0 c (a :: q) item_match seq_list_match
) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.OnRange.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Steel.ST.SeqMatch.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.OnRange",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
c: FStar.Seq.Base.seq t ->
v: Prims.list t' ->
item_match: (_: t -> v': t'{v' << v} -> Steel.Effect.Common.vprop)
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"FStar.Seq.Base.seq",
"Prims.list",
"Prims.precedes",
"Steel.Effect.Common.vprop",
"Steel.ST.Util.rewrite",
"Steel.ST.SeqMatch.seq_list_match_nil0",
"Steel.ST.SeqMatch.seq_list_match",
"Prims.unit",
"Steel.ST.Util.noop",
"Steel.Effect.Common.emp",
"Prims.l_and",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.empty",
"Prims.b2t",
"Prims.uu___is_Nil",
"Prims.l_True"
] | [] | false | true | false | false | false | let seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> v': t'{v' << v} -> vprop))
: STGhost unit
opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\ Nil? v)
(fun _ -> True) =
| noop ();
rewrite (seq_list_match_nil0 c) (seq_list_match c v item_match) | false |
FStar.UInt.fst | FStar.UInt.logand_commutative | val logand_commutative: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True) (ensures (logand #n a b = logand #n b a)) | val logand_commutative: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True) (ensures (logand #n a b = logand #n b a)) | let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 76,
"end_line": 170,
"start_col": 0,
"start_line": 170
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logand a b = FStar.UInt.logand b a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logand",
"Prims.unit"
] | [] | true | false | true | false | false | let logand_commutative #n a b =
| nth_lemma #n (logand #n a b) (logand #n b a) | false |
FStar.UInt.fst | FStar.UInt.logand_associative | val logand_associative: #n:pos -> a:uint_t n -> b:uint_t n -> c:uint_t n ->
Lemma (requires True)
(ensures (logand #n (logand #n a b) c = logand #n a (logand #n b c))) | val logand_associative: #n:pos -> a:uint_t n -> b:uint_t n -> c:uint_t n ->
Lemma (requires True)
(ensures (logand #n (logand #n a b) c = logand #n a (logand #n b c))) | let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 106,
"end_line": 172,
"start_col": 0,
"start_line": 172
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> c: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.logand (FStar.UInt.logand a b) c = FStar.UInt.logand a (FStar.UInt.logand b c)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logand",
"Prims.unit"
] | [] | true | false | true | false | false | let logand_associative #n a b c =
| nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c)) | false |
FStar.UInt.fst | FStar.UInt.logand_self | val logand_self: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logand #n a a = a)) | val logand_self: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logand #n a a = a)) | let logand_self #n a = nth_lemma #n (logand #n a a) a | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 174,
"start_col": 0,
"start_line": 174
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> FStar.Pervasives.Lemma (ensures FStar.UInt.logand a a = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logand",
"Prims.unit"
] | [] | true | false | true | false | false | let logand_self #n a =
| nth_lemma #n (logand #n a a) a | false |
FStar.UInt.fst | FStar.UInt.logand_lemma_1 | val logand_lemma_1: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) | val logand_lemma_1: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) | let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 176,
"start_col": 0,
"start_line": 176
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logand a (FStar.UInt.zero n) = FStar.UInt.zero n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logand",
"FStar.UInt.zero",
"Prims.unit"
] | [] | true | false | true | false | false | let logand_lemma_1 #n a =
| nth_lemma #n (logand #n a (zero n)) (zero n) | false |
FStar.UInt.fst | FStar.UInt.logand_lemma_2 | val logand_lemma_2: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logand #n a (ones n) = a)) | val logand_lemma_2: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logand #n a (ones n) = a)) | let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 178,
"start_col": 0,
"start_line": 178
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logand a (FStar.UInt.ones n) = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logand",
"FStar.UInt.ones",
"Prims.unit"
] | [] | true | false | true | false | false | let logand_lemma_2 #n a =
| nth_lemma #n (logand #n a (ones n)) a | false |
FStar.UInt.fst | FStar.UInt.logxor_self | val logxor_self: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logxor #n a a = zero n)) | val logxor_self: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logxor #n a a = zero n)) | let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 196,
"start_col": 0,
"start_line": 196
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> FStar.Pervasives.Lemma (ensures FStar.UInt.logxor a a = FStar.UInt.zero n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logxor",
"FStar.UInt.zero",
"Prims.unit"
] | [] | true | false | true | false | false | let logxor_self #n a =
| nth_lemma #n (logxor #n a a) (zero n) | false |
FStar.UInt.fst | FStar.UInt.logand_le | val logand_le: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True)
(ensures (logand a b) <= a /\ (logand a b) <= b) | val logand_le: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True)
(ensures (logand a b) <= a /\ (logand a b) <= b) | let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 190,
"start_col": 0,
"start_line": 185
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logand a b <= a /\ FStar.UInt.logand a b <= b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.subset_vec_le_lemma",
"Prims.unit",
"FStar.BitVector.bv_t",
"FStar.UInt.to_vec",
"FStar.UInt.logand"
] | [] | true | false | true | false | false | let logand_le #n a b =
| let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb | false |
FStar.UInt.fst | FStar.UInt.logxor_commutative | val logxor_commutative: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) | val logxor_commutative: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) | let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 76,
"end_line": 192,
"start_col": 0,
"start_line": 192
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logxor a b = FStar.UInt.logxor b a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logxor",
"Prims.unit"
] | [] | true | false | true | false | false | let logxor_commutative #n a b =
| nth_lemma #n (logxor #n a b) (logxor #n b a) | false |
FStar.UInt.fst | FStar.UInt.logxor_associative | val logxor_associative: #n:pos -> a:uint_t n -> b:uint_t n -> c:uint_t n ->
Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c))) | val logxor_associative: #n:pos -> a:uint_t n -> b:uint_t n -> c:uint_t n ->
Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c))) | let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 106,
"end_line": 194,
"start_col": 0,
"start_line": 194
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> c: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.logxor (FStar.UInt.logxor a b) c = FStar.UInt.logxor a (FStar.UInt.logxor b c)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logxor",
"Prims.unit"
] | [] | true | false | true | false | false | let logxor_associative #n a b c =
| nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c)) | false |
FStar.UInt.fst | FStar.UInt.logxor_lemma_2 | val logxor_lemma_2: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a)) | val logxor_lemma_2: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a)) | let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 200,
"start_col": 0,
"start_line": 200
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logxor a (FStar.UInt.ones n) = FStar.UInt.lognot a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logxor",
"FStar.UInt.ones",
"FStar.UInt.lognot",
"Prims.unit"
] | [] | true | false | true | false | false | let logxor_lemma_2 #n a =
| nth_lemma #n (logxor #n a (ones n)) (lognot #n a) | false |
CQueue.fst | CQueue.elim_llist_fragment_head_cons | val elim_llist_fragment_head_cons
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (ll_uncons_t a) opened
(llist_fragment_head l phead head)
(fun res -> ccell head `star` llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next)
(fun _ -> Cons? (Ghost.reveal l))
(fun h res h' ->
ccell_ptrvalue_is_null head == false /\
Ghost.reveal l == (h' (ccell head)).vcell_data :: Ghost.reveal res.ll_uncons_tl /\
Ghost.reveal res.ll_uncons_pnext == ccell_next head /\
Ghost.reveal res.ll_uncons_next == (h' (ccell head)).vcell_next /\
h' (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) == h (llist_fragment_head l phead head)
) | val elim_llist_fragment_head_cons
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (ll_uncons_t a) opened
(llist_fragment_head l phead head)
(fun res -> ccell head `star` llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next)
(fun _ -> Cons? (Ghost.reveal l))
(fun h res h' ->
ccell_ptrvalue_is_null head == false /\
Ghost.reveal l == (h' (ccell head)).vcell_data :: Ghost.reveal res.ll_uncons_tl /\
Ghost.reveal res.ll_uncons_pnext == ccell_next head /\
Ghost.reveal res.ll_uncons_next == (h' (ccell head)).vcell_next /\
h' (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) == h (llist_fragment_head l phead head)
) | let elim_llist_fragment_head_cons
#_ #a l0 phead head
=
let l : (l : Ghost.erased (list a) { Cons? l }) = l0 in
change_equal_slprop
(llist_fragment_head l0 phead head)
(llist_fragment_head l phead head);
llist_fragment_head_eq_cons l phead head;
change_equal_slprop
(llist_fragment_head l phead head)
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l))));
let x = elim_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)))
in
let head2 = gget (ccell_is_lvalue head) in
elim_ccell_is_lvalue head;
elim_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l));
let vhead2 = gget (ccell head) in
let res = {
ll_uncons_pnext = ccell_next head2;
ll_uncons_next = vhead2.vcell_next;
ll_uncons_tl = L.tl l;
} in
change_equal_slprop
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)) (Ghost.reveal x))
(llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next);
res | {
"file_name": "share/steel/examples/steel/CQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 938,
"start_col": 0,
"start_line": 907
} | module CQueue
open CQueue.LList
#set-options "--ide_id_info_off"
//Re-define squash, since this module explicitly
//replies on proving equalities of the form `t_of v == squash p`
//which are delicate in the presence of optimizations that
//unfold `Prims.squash (p /\ q)`to _:unit{p /\ q}
//See Issue #2496
let squash (p:Type u#a) : Type0 = squash p
(* BEGIN library *)
let intro_vrewrite_no_norm (#opened:inames)
(v: vprop) (#t: Type) (f: (t_of v) -> GTot t)
: SteelGhost unit opened v (fun _ -> vrewrite v f)
(fun _ -> True) (fun h _ h' -> h' (vrewrite v f) == f (h v))
=
intro_vrewrite v f
let elim_vrewrite_no_norm (#opened:inames)
(v: vprop)
(#t: Type)
(f: ((t_of v) -> GTot t))
: SteelGhost unit opened (vrewrite v f) (fun _ -> v)
(fun _ -> True)
(fun h _ h' -> h (vrewrite v f) == f (h' v))
=
elim_vrewrite v f
let vconst_sel
(#a: Type)
(x: a)
: Tot (selector a (hp_of emp))
= fun _ -> x
[@@ __steel_reduce__]
let vconst'
(#a: Type)
(x: a)
: GTot vprop'
= {
hp = hp_of emp;
t = a;
sel = vconst_sel x;
}
[@@ __steel_reduce__]
let vconst (#a: Type) (x: a) : Tot vprop = VUnit (vconst' x)
let intro_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
emp
(fun _ -> vconst x)
(fun _ -> True)
(fun _ _ h' -> h' (vconst x) == x)
=
change_slprop_rel
emp
(vconst x)
(fun _ y -> y == x)
(fun _ -> ())
let elim_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
(vconst x)
(fun _ -> emp)
(fun _ -> True)
(fun h _ _ -> h (vconst x) == x)
=
change_slprop_rel
(vconst x)
emp
(fun y _ -> y == x)
(fun _ -> ())
let vpure_sel'
(p: prop)
: Tot (selector' (squash p) (Steel.Memory.pure p))
= fun (m: Steel.Memory.hmem (Steel.Memory.pure p)) -> pure_interp p m
let vpure_sel
(p: prop)
: Tot (selector (squash p) (Steel.Memory.pure p))
= vpure_sel' p
[@@ __steel_reduce__]
let vpure'
(p: prop)
: GTot vprop'
= {
hp = Steel.Memory.pure p;
t = squash p;
sel = vpure_sel p;
}
[@@ __steel_reduce__]
let vpure (p: prop) : Tot vprop = VUnit (vpure' p)
let intro_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
emp
(fun _ -> vpure p)
(fun _ -> p)
(fun _ _ h' -> p)
=
change_slprop_rel
emp
(vpure p)
(fun _ _ -> p)
(fun m -> pure_interp p m)
let elim_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
(vpure p)
(fun _ -> emp)
(fun _ -> True)
(fun _ _ _ -> p)
=
change_slprop_rel
(vpure p)
emp
(fun _ _ -> p)
(fun m -> pure_interp p m; reveal_emp (); intro_emp m)
val intro_vdep2 (#opened:inames)
(v: vprop)
(q: vprop)
(x: t_of v)
(p: (t_of v -> Tot vprop))
: SteelGhost unit opened
(v `star` q)
(fun _ -> vdep v p)
(requires (fun h ->
q == p x /\
x == h v
))
(ensures (fun h _ h' ->
let x2 = h' (vdep v p) in
q == p (h v) /\
dfst x2 == (h v) /\
dsnd x2 == (h q)
))
let intro_vdep2
v q x p
=
intro_vdep v q p
let vbind0_payload
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: t_of a)
: Tot vprop
= vpure (t == t_of (b x)) `star` b x
let vbind0_rewrite
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: normal (t_of (vdep a (vbind0_payload a t b))))
: Tot t
= snd (dsnd x)
[@@__steel_reduce__; __reduce__]
let vbind0
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= a `vdep` vbind0_payload a t b `vrewrite` vbind0_rewrite a t b
let vbind_hp // necessary to hide the attribute on hp_of
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot (slprop u#1)
= hp_of (vbind0 a t b)
let vbind_sel // same for hp_sel
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot (selector t (vbind_hp a t b))
= sel_of (vbind0 a t b)
[@@__steel_reduce__]
let vbind'
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot vprop'
= {
hp = vbind_hp a t b;
t = t;
sel = vbind_sel a t b;
}
[@@__steel_reduce__]
let vbind
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= VUnit (vbind' a t b)
let intro_vbind
(#opened: _)
(a: vprop)
(b' : vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost unit opened
(a `star` b')
(fun _ -> vbind a t b)
(fun h -> t_of b' == t /\ b' == b (h a))
(fun h _ h' ->
t_of b' == t /\
b' == b (h a) /\
h' (vbind a t b) == h b'
)
=
intro_vpure (t == t_of b');
intro_vdep
a
(vpure (t == t_of b') `star` b')
(vbind0_payload a t b);
intro_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
change_slprop_rel
(vbind0 a t b)
(vbind a t b)
(fun x y -> x == y)
(fun _ -> ())
let elim_vbind
(#opened: _)
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a)) opened
(vbind a t b)
(fun res -> a `star` b (Ghost.reveal res))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\
t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)
)
=
change_slprop_rel
(vbind a t b)
(vbind0 a t b)
(fun x y -> x == y)
(fun _ -> ());
elim_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
let res = elim_vdep a (vbind0_payload a t b) in
change_equal_slprop
(vbind0_payload a t b (Ghost.reveal res))
(vpure (t == t_of (b (Ghost.reveal res))) `star` b (Ghost.reveal res));
elim_vpure (t == t_of (b (Ghost.reveal res)));
res
let (==) (#a:_) (x y: a) : prop = x == y
let snoc_inj (#a: Type) (hd1 hd2: list a) (tl1 tl2: a) : Lemma
(requires (hd1 `L.append` [tl1] == hd2 `L.append` [tl2]))
(ensures (hd1 == hd2 /\ tl1 == tl2))
[SMTPat (hd1 `L.append` [tl1]); SMTPat (hd2 `L.append` [tl2])]
= L.lemma_snoc_unsnoc (hd1, tl1);
L.lemma_snoc_unsnoc (hd2, tl2)
[@"opaque_to_smt"]
let unsnoc (#a: Type) (l: list a) : Pure (list a & a)
(requires (Cons? l))
(ensures (fun (hd, tl) -> l == hd `L.append` [tl] /\ L.length hd < L.length l))
=
L.lemma_unsnoc_snoc l;
L.append_length (fst (L.unsnoc l)) [snd (L.unsnoc l)];
L.unsnoc l
let unsnoc_hd (#a: Type) (l: list a) : Pure (list a) (requires (Cons? l)) (ensures (fun l' -> L.length l' <
L.length l)) = fst (unsnoc l)
let unsnoc_tl (#a: Type) (l: list a) : Pure (a) (requires (Cons? l)) (ensures (fun _ -> True)) = snd (unsnoc l)
[@@"opaque_to_smt"]
let snoc (#a: Type) (l: list a) (x: a) : Pure (list a)
(requires True)
(ensures (fun l' ->
Cons? l' /\
unsnoc_hd l' == l /\
unsnoc_tl l' == x
))
=
let l' = L.snoc (l, x) in
L.append_length l [x];
snoc_inj l (unsnoc_hd l') x (unsnoc_tl l');
l'
let snoc_unsnoc
(#a: Type)
(l: list a)
: Lemma
(requires (Cons? l))
(ensures (snoc (unsnoc_hd l) (unsnoc_tl l) == l))
= ()
unfold
let coerce
(#a: Type)
(x: a)
(b: Type)
: Pure b
(requires (a == b))
(ensures (fun y -> a == b /\ x == y))
= x
(* END library *)
let t a = cllist_lvalue a
let v (a: Type0) = list a
let datas
(#a: Type0)
(l: v a)
: Tot (list a)
= l
(* view from the tail *)
let llist_fragment_tail_cons_data_refine
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(d: a)
: Tot prop
= d == unsnoc_tl (Ghost.reveal l)
[@@ __steel_reduce__]
let llist_fragment_tail_cons_lvalue_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(c: ccell_lvalue a)
: Tot vprop
= vptr (ccell_data c) `vrefine` llist_fragment_tail_cons_data_refine l
let ccell_is_lvalue_refine
(a: Type)
(c: ccell_ptrvalue a)
: Tot prop
= ccell_ptrvalue_is_null c == false
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_next_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(ptail: ref (ccell_ptrvalue a))
: Tot vprop
= vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_rewrite
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(llist_fragment_tail: vprop { t_of llist_fragment_tail == ref (ccell_ptrvalue a) })
(x: normal (t_of (llist_fragment_tail `vdep` (llist_fragment_tail_cons_next_payload l))))
: Tot (ref (ccell_ptrvalue a))
= let (| _, (| c, _ |) |) = x in
ccell_next c
let rec llist_fragment_tail (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : Pure vprop
(requires True)
(ensures (fun v -> t_of v == ref (ccell_ptrvalue a)))
(decreases (Ghost.reveal (L.length l)))
= if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
let llist_fragment_tail_eq
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
= assert_norm
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
let llist_fragment_tail_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(requires (Cons? l))
(ensures (Cons? l /\
llist_fragment_tail l phead == (
llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
)))
= llist_fragment_tail_eq l phead
unfold
let sel_llist_fragment_tail
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_tail l phead) /\ True) })
: GTot (ref (ccell_ptrvalue a))
=
coerce (h (llist_fragment_tail l phead)) (ref (ccell_ptrvalue a))
val intro_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_tail l phead)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_tail l phead h' == phead)
let intro_llist_fragment_tail_nil
l phead
=
intro_vconst phead;
change_equal_slprop
(vconst phead)
(llist_fragment_tail l phead)
val elim_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l phead)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_tail l phead h == phead)
let elim_llist_fragment_tail_nil
l phead
=
change_equal_slprop
(llist_fragment_tail l phead)
(vconst phead);
elim_vconst phead
val intro_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(ptail: Ghost.erased (ref (ccell_ptrvalue a)))
(tail: Ghost.erased (ccell_lvalue a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l phead `star` vptr ptail `star` vptr (ccell_data tail))
(fun res -> llist_fragment_tail res phead)
(fun h ->
sel_llist_fragment_tail l phead h == Ghost.reveal ptail /\
sel ptail h == Ghost.reveal tail
)
(fun h res h' ->
Ghost.reveal res == snoc (Ghost.reveal l) (sel (ccell_data tail) h) /\
sel_llist_fragment_tail res phead h' == ccell_next tail
)
#push-options "--z3rlimit 16"
let intro_llist_fragment_tail_snoc
#_ #a l phead ptail tail
=
let d = gget (vptr (ccell_data tail)) in
let l' : (l' : Ghost.erased (list a) { Cons? (Ghost.reveal l') }) = Ghost.hide (snoc (Ghost.reveal l) (Ghost.reveal d)) in
intro_vrefine (vptr (ccell_data tail)) (llist_fragment_tail_cons_data_refine l');
intro_vrefine (vptr ptail) (ccell_is_lvalue_refine a);
intro_vdep
(vptr ptail `vrefine` ccell_is_lvalue_refine a)
(vptr (ccell_data tail) `vrefine` llist_fragment_tail_cons_data_refine l')
(llist_fragment_tail_cons_lvalue_payload l');
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead);
intro_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead)
(vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l')
(llist_fragment_tail_cons_next_payload l');
intro_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l')
(llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead));
llist_fragment_tail_eq_cons l' phead;
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l' `vrewrite` llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead))
(llist_fragment_tail l' phead);
let g' = gget (llist_fragment_tail l' phead) in
assert (Ghost.reveal g' == ccell_next tail);
noop ();
l'
#pop-options
[@@erasable]
noeq
type ll_unsnoc_t (a: Type) = {
ll_unsnoc_l: list a;
ll_unsnoc_ptail: ref (ccell_ptrvalue a);
ll_unsnoc_tail: ccell_lvalue a;
}
val elim_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost (ll_unsnoc_t a) opened
(llist_fragment_tail l phead)
(fun res -> llist_fragment_tail res.ll_unsnoc_l phead `star` vptr res.ll_unsnoc_ptail `star` vptr (ccell_data res.ll_unsnoc_tail))
(fun _ -> Cons? l)
(fun h res h' ->
Cons? l /\
Ghost.reveal res.ll_unsnoc_l == unsnoc_hd l /\
sel res.ll_unsnoc_ptail h' == res.ll_unsnoc_tail /\
sel (ccell_data res.ll_unsnoc_tail) h'== unsnoc_tl l /\
sel_llist_fragment_tail res.ll_unsnoc_l phead h' == res.ll_unsnoc_ptail /\
sel_llist_fragment_tail l phead h == (ccell_next res.ll_unsnoc_tail)
)
#push-options "--z3rlimit 32"
#restart-solver
let elim_llist_fragment_tail_snoc
#_ #a l phead
=
let l0 : (l0: Ghost.erased (list a) { Cons? l0 }) = Ghost.hide (Ghost.reveal l) in
llist_fragment_tail_eq_cons l0 phead;
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0 `vrewrite` llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
elim_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0)
(llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
let ptail = elim_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail_cons_next_payload l0)
in
let ptail0 : Ghost.erased (ref (ccell_ptrvalue a)) = ptail in
change_equal_slprop
(llist_fragment_tail_cons_next_payload l0 (Ghost.reveal ptail))
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l0);
let tail = elim_vdep
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a)
(llist_fragment_tail_cons_lvalue_payload l0)
in
elim_vrefine (vptr (Ghost.reveal ptail0)) (ccell_is_lvalue_refine a);
let res = {
ll_unsnoc_l = unsnoc_hd l0;
ll_unsnoc_ptail = Ghost.reveal ptail0;
ll_unsnoc_tail = Ghost.reveal tail;
} in
change_equal_slprop
(vptr (Ghost.reveal ptail0))
(vptr res.ll_unsnoc_ptail);
change_equal_slprop
(llist_fragment_tail_cons_lvalue_payload l0 (Ghost.reveal tail))
(vptr (ccell_data res.ll_unsnoc_tail) `vrefine` llist_fragment_tail_cons_data_refine l0);
elim_vrefine
(vptr (ccell_data res.ll_unsnoc_tail))
(llist_fragment_tail_cons_data_refine l0);
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail res.ll_unsnoc_l phead);
res
#pop-options
let rec llist_fragment_tail_append
(#opened: _)
(#a: Type)
(phead0: ref (ccell_ptrvalue a))
(l1: Ghost.erased (list a))
(phead1: Ghost.erased (ref (ccell_ptrvalue a)))
(l2: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l1 phead0 `star` llist_fragment_tail l2 phead1)
(fun res -> llist_fragment_tail res phead0)
(fun h ->
Ghost.reveal phead1 == (sel_llist_fragment_tail l1 phead0) h
)
(fun h res h' ->
Ghost.reveal res == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
(sel_llist_fragment_tail res phead0) h' == (sel_llist_fragment_tail l2 phead1) h
)
(decreases (L.length (Ghost.reveal l2)))
=
let g1 = gget (llist_fragment_tail l1 phead0) in
assert (Ghost.reveal phead1 == Ghost.reveal g1);
if Nil? l2
then begin
L.append_l_nil (Ghost.reveal l1);
elim_llist_fragment_tail_nil l2 phead1;
l1
end else begin
let res = elim_llist_fragment_tail_snoc l2 (Ghost.reveal phead1) in
let d = gget (vptr (ccell_data res.ll_unsnoc_tail)) in
L.append_assoc (Ghost.reveal l1) (Ghost.reveal res.ll_unsnoc_l) [Ghost.reveal d];
let l3 = llist_fragment_tail_append phead0 l1 phead1 res.ll_unsnoc_l in
intro_llist_fragment_tail_snoc l3 phead0 res.ll_unsnoc_ptail res.ll_unsnoc_tail
end
let queue_tail_refine
(#a: Type)
(tail1: ref (ccell_ptrvalue a))
(tail2: ref (ccell_ptrvalue a))
(tl: normal (t_of (vptr tail2)))
: Tot prop
= ccell_ptrvalue_is_null tl == true /\ tail1 == tail2
[@@__steel_reduce__]
let queue_tail_dep2
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
(tail2: ref (ccell_ptrvalue a))
: Tot vprop
= vptr tail2 `vrefine` queue_tail_refine tail1 tail2
[@@__steel_reduce__]
let queue_tail_dep1
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
: Tot vprop
= vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail1
[@@__steel_reduce__; __reduce__]
let queue_tail
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: Tot vprop
=
llist_fragment_tail l (cllist_head x) `vdep` queue_tail_dep1 x l
val intro_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun _ -> queue_tail x l)
(fun h ->
sel_llist_fragment_tail l (cllist_head x) h == tail /\
sel (cllist_tail x) h == tail /\
ccell_ptrvalue_is_null (sel tail h)
)
(fun _ _ _ -> True)
let intro_queue_tail
x l tail
=
intro_vrefine (vptr tail) (queue_tail_refine tail tail);
intro_vdep2
(vptr (cllist_tail x))
(vptr tail `vrefine` queue_tail_refine tail tail)
tail
(queue_tail_dep2 x l tail);
intro_vdep2
(llist_fragment_tail l (cllist_head x))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail)
tail
(queue_tail_dep1 x l)
val elim_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened
(queue_tail x l)
(fun tail -> llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun h -> True)
(fun _ tail h ->
sel_llist_fragment_tail l (cllist_head x) h == Ghost.reveal tail /\
sel (cllist_tail x) h == Ghost.reveal tail /\
ccell_ptrvalue_is_null (h (vptr tail))
)
let elim_queue_tail
#_ #a x l
=
let tail0 = elim_vdep
(llist_fragment_tail l (cllist_head x))
(queue_tail_dep1 x l)
in
let tail : Ghost.erased (ref (ccell_ptrvalue a)) = tail0 in
change_equal_slprop
(queue_tail_dep1 x l (Ghost.reveal tail0))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail0);
let tail2 = elim_vdep
(vptr (cllist_tail x))
(queue_tail_dep2 x l tail0)
in
let tail3 : Ghost.erased (ref (ccell_ptrvalue a)) = tail2 in
change_equal_slprop
(queue_tail_dep2 x l tail0 (Ghost.reveal tail2))
(vptr tail3 `vrefine` queue_tail_refine tail0 tail3);
elim_vrefine (vptr tail3) (queue_tail_refine tail0 tail3);
change_equal_slprop
(vptr tail3)
(vptr tail);
tail
(* view from the head *)
let llist_fragment_head_data_refine
(#a: Type)
(d: a)
(c: vcell a)
: Tot prop
= c.vcell_data == d
let llist_fragment_head_payload
(#a: Type)
(head: ccell_ptrvalue a)
(d: a)
(llist_fragment_head: (ref (ccell_ptrvalue a) -> ccell_ptrvalue a -> Tot vprop))
(x: t_of (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine d)))
: Tot vprop
=
llist_fragment_head (ccell_next (fst x)) (snd x).vcell_next
let rec llist_fragment_head (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : Tot vprop
(decreases (Ghost.reveal l))
=
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
let t_of_llist_fragment_head
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(t_of (llist_fragment_head l phead head) == ref (ccell_ptrvalue a) & ccell_ptrvalue a)
= ()
unfold
let sel_llist_fragment_head
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_head l phead head) /\ True) })
: GTot (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
=
coerce (h (llist_fragment_head l phead head)) (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
val intro_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_head l phead head)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_head l phead head h' == (phead, head))
let intro_llist_fragment_head_nil
l phead head
=
intro_vconst (phead, head);
change_equal_slprop
(vconst (phead, head))
(llist_fragment_head l phead head)
val elim_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_head l phead head h == (phead, head))
let elim_llist_fragment_head_nil
l phead head
=
change_equal_slprop
(llist_fragment_head l phead head)
(vconst (phead, head));
elim_vconst (phead, head)
let llist_fragment_head_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(requires (Cons? (Ghost.reveal l)))
(ensures (
llist_fragment_head l phead head ==
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
= assert_norm
(llist_fragment_head l phead head == (
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
val intro_llist_fragment_head_cons
(#opened: _)
(#a: Type) (phead: ref (ccell_ptrvalue a)) (head: ccell_lvalue a) (next: (ccell_ptrvalue a)) (tl: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(ccell head `star` llist_fragment_head tl (ccell_next head) next)
(fun res -> llist_fragment_head res phead head)
(fun h -> (h (ccell head)).vcell_next == next)
(fun h res h' ->
Ghost.reveal res == (h (ccell head)).vcell_data :: Ghost.reveal tl /\
h' (llist_fragment_head res phead head) == h (llist_fragment_head tl (ccell_next head) next)
)
let intro_llist_fragment_head_cons
#_ #a phead head next tl
=
let vc = gget (ccell head) in
let l' : (l' : Ghost.erased (list a) { Cons? l' }) = Ghost.hide (vc.vcell_data :: tl) in
intro_ccell_is_lvalue head;
intro_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l'));
intro_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(llist_fragment_head tl (ccell_next head) next)
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l')));
llist_fragment_head_eq_cons l' phead head;
change_equal_slprop
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l'))))
(llist_fragment_head l' phead head);
l'
[@@erasable]
noeq
type ll_uncons_t
(a: Type)
= {
ll_uncons_pnext: Ghost.erased (ref (ccell_ptrvalue a));
ll_uncons_next: Ghost.erased (ccell_ptrvalue a);
ll_uncons_tl: Ghost.erased (list a);
}
val elim_llist_fragment_head_cons
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (ll_uncons_t a) opened
(llist_fragment_head l phead head)
(fun res -> ccell head `star` llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next)
(fun _ -> Cons? (Ghost.reveal l))
(fun h res h' ->
ccell_ptrvalue_is_null head == false /\
Ghost.reveal l == (h' (ccell head)).vcell_data :: Ghost.reveal res.ll_uncons_tl /\
Ghost.reveal res.ll_uncons_pnext == ccell_next head /\
Ghost.reveal res.ll_uncons_next == (h' (ccell head)).vcell_next /\
h' (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) == h (llist_fragment_head l phead head)
) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"CQueue.LList.fsti.checked"
],
"interface_file": true,
"source_file": "CQueue.fst"
} | [
{
"abbrev": false,
"full_module": "CQueue.LList",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
l: FStar.Ghost.erased (Prims.list a) ->
phead: Steel.Reference.ref (CQueue.Cell.ccell_ptrvalue a) ->
head: CQueue.Cell.ccell_ptrvalue a
-> Steel.Effect.Atomic.SteelGhost (CQueue.ll_uncons_t a) | Steel.Effect.Atomic.SteelGhost | [] | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Prims.list",
"Steel.Reference.ref",
"CQueue.Cell.ccell_ptrvalue",
"CQueue.ll_uncons_t",
"Prims.unit",
"Steel.Effect.Atomic.change_equal_slprop",
"CQueue.llist_fragment_head_payload",
"FStar.List.Tot.Base.hd",
"FStar.Ghost.reveal",
"CQueue.llist_fragment_head",
"FStar.Ghost.hide",
"FStar.List.Tot.Base.tl",
"Steel.Effect.Common.t_of",
"Steel.Effect.Common.star",
"CQueue.Cell.ccell_is_lvalue",
"Steel.Effect.Common.vrefine",
"CQueue.Cell.ccell",
"CQueue.llist_fragment_head_data_refine",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_tl",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_pnext",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_next",
"CQueue.Mkll_uncons_t",
"CQueue.Cell.ccell_next",
"CQueue.Cell.__proj__Mkvcell__item__vcell_next",
"Steel.Effect.Atomic.gget",
"Steel.Effect.Atomic.elim_vrefine",
"CQueue.Cell.elim_ccell_is_lvalue",
"CQueue.elim_vbind",
"FStar.Pervasives.Native.tuple2",
"CQueue.vbind",
"CQueue.llist_fragment_head_eq_cons",
"Prims.b2t",
"Prims.uu___is_Cons"
] | [] | false | true | false | false | false | let elim_llist_fragment_head_cons #_ #a l0 phead head =
| let l:(l: Ghost.erased (list a) {Cons? l}) = l0 in
change_equal_slprop (llist_fragment_head l0 phead head) (llist_fragment_head l phead head);
llist_fragment_head_eq_cons l phead head;
change_equal_slprop (llist_fragment_head l phead head)
(vbind ((ccell_is_lvalue head)
`star`
((ccell head) `vrefine` (llist_fragment_head_data_refine (L.hd l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l))));
let x =
elim_vbind ((ccell_is_lvalue head)
`star`
((ccell head) `vrefine` (llist_fragment_head_data_refine (L.hd l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)))
in
let head2 = gget (ccell_is_lvalue head) in
elim_ccell_is_lvalue head;
elim_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l));
let vhead2 = gget (ccell head) in
let res =
{ ll_uncons_pnext = ccell_next head2; ll_uncons_next = vhead2.vcell_next; ll_uncons_tl = L.tl l }
in
change_equal_slprop (llist_fragment_head_payload head
(L.hd l)
(llist_fragment_head (L.tl l))
(Ghost.reveal x))
(llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next);
res | false |
FStar.UInt.fst | FStar.UInt.logxor_lemma_1 | val logxor_lemma_1: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logxor #n a (zero n) = a)) | val logxor_lemma_1: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logxor #n a (zero n) = a)) | let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 198,
"start_col": 0,
"start_line": 198
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logxor a (FStar.UInt.zero n) = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logxor",
"FStar.UInt.zero",
"Prims.unit"
] | [] | true | false | true | false | false | let logxor_lemma_1 #n a =
| nth_lemma #n (logxor #n a (zero n)) a | false |
FStar.UInt.fst | FStar.UInt.subset_vec_le_lemma | val subset_vec_le_lemma: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires is_subset_vec #n a b) (ensures (from_vec a) <= (from_vec b)) | val subset_vec_le_lemma: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires is_subset_vec #n a b) (ensures (from_vec a) <= (from_vec b)) | let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 183,
"start_col": 0,
"start_line": 180
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.BitVector.bv_t n -> b: FStar.BitVector.bv_t n
-> FStar.Pervasives.Lemma (requires FStar.BitVector.is_subset_vec a b)
(ensures FStar.UInt.from_vec a <= FStar.UInt.from_vec b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.BitVector.bv_t",
"Prims.int",
"FStar.UInt.subset_vec_le_lemma",
"Prims.op_Subtraction",
"FStar.Seq.Base.slice",
"Prims.bool",
"Prims.unit",
"FStar.BitVector.lemma_slice_subset_vec"
] | [
"recursion"
] | false | false | true | false | false | let rec subset_vec_le_lemma #n a b =
| match n with
| 1 -> ()
| _ ->
lemma_slice_subset_vec #n a b 0 (n - 1);
subset_vec_le_lemma #(n - 1) (slice a 0 (n - 1)) (slice b 0 (n - 1)) | false |
FStar.UInt.fst | FStar.UInt.logxor_inv | val logxor_inv: #n:pos -> a:uint_t n -> b:uint_t n -> Lemma
(a = logxor #n (logxor #n a b) b) | val logxor_inv: #n:pos -> a:uint_t n -> b:uint_t n -> Lemma
(a = logxor #n (logxor #n a b) b) | let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 216,
"start_col": 0,
"start_line": 204
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures a = FStar.UInt.logxor (FStar.UInt.logxor a b) b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.inverse_num_lemma",
"Prims.unit",
"FStar.Seq.Base.lemma_eq_intro",
"Prims.bool",
"FStar.BitVector.logxor_vec",
"Prims.cut",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"FStar.Seq.Base.index",
"FStar.UInt.xor",
"Prims.op_disEquality",
"FStar.BitVector.bv_t",
"FStar.UInt.to_vec"
] | [] | false | false | true | false | false | let logxor_inv #n a b =
| let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut (forall (i: nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i: nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==>
index (logxor_vec (logxor_vec va vb) vb) i =
(xor (xor (index va i) (index vb i)) (index vb i)));
cut (forall (i: nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a;
inverse_num_lemma b | false |
FStar.UInt.fst | FStar.UInt.logxor_neq_nonzero | val logxor_neq_nonzero: #n:pos -> a:uint_t n -> b:uint_t n -> Lemma
(a <> b ==> logxor a b <> 0) | val logxor_neq_nonzero: #n:pos -> a:uint_t n -> b:uint_t n -> Lemma
(a <> b ==> logxor a b <> 0) | let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 229,
"start_col": 0,
"start_line": 218
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures a <> b ==> FStar.UInt.logxor a b <> 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.logxor",
"Prims._assert",
"Prims.b2t",
"FStar.UInt.from_vec",
"Prims.unit",
"FStar.Seq.Base.lemma_eq_intro",
"Prims.bool",
"Prims.l_Forall",
"Prims.nat",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"FStar.Classical.forall_intro",
"Prims.op_Negation",
"FStar.UInt.nth",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.UInt.zero_nth_lemma",
"FStar.BitVector.bv_t",
"FStar.UInt.to_vec"
] | [] | false | false | true | false | false | let logxor_neq_nonzero #n a b =
| let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0
then
let open FStar.Seq in
let f (i: nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i: nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb) | false |
FStar.UInt.fst | FStar.UInt.logor_commutative | val logor_commutative: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True) (ensures (logor #n a b = logor #n b a)) | val logor_commutative: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True) (ensures (logor #n a b = logor #n b a)) | let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 73,
"end_line": 231,
"start_col": 0,
"start_line": 231
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logor a b = FStar.UInt.logor b a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logor",
"Prims.unit"
] | [] | true | false | true | false | false | let logor_commutative #n a b =
| nth_lemma #n (logor #n a b) (logor #n b a) | false |
FStar.UInt.fst | FStar.UInt.logor_lemma_1 | val logor_lemma_1: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logor #n a (zero n) = a)) | val logor_lemma_1: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logor #n a (zero n) = a)) | let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 237,
"start_col": 0,
"start_line": 237
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logor a (FStar.UInt.zero n) = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logor",
"FStar.UInt.zero",
"Prims.unit"
] | [] | true | false | true | false | false | let logor_lemma_1 #n a =
| nth_lemma (logor #n a (zero n)) a | false |
FStar.UInt.fst | FStar.UInt.superset_vec_ge_lemma | val superset_vec_ge_lemma: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires is_superset_vec #n a b)
(ensures (from_vec a) >= (from_vec b)) | val superset_vec_ge_lemma: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires is_superset_vec #n a b)
(ensures (from_vec a) >= (from_vec b)) | let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 244,
"start_col": 0,
"start_line": 241
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.BitVector.bv_t n -> b: FStar.BitVector.bv_t n
-> FStar.Pervasives.Lemma (requires FStar.BitVector.is_superset_vec a b)
(ensures FStar.UInt.from_vec a >= FStar.UInt.from_vec b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.BitVector.bv_t",
"Prims.int",
"FStar.UInt.superset_vec_ge_lemma",
"Prims.op_Subtraction",
"FStar.Seq.Base.slice",
"Prims.bool",
"Prims.unit",
"FStar.BitVector.lemma_slice_superset_vec"
] | [
"recursion"
] | false | false | true | false | false | let rec superset_vec_ge_lemma #n a b =
| match n with
| 1 -> ()
| _ ->
lemma_slice_superset_vec #n a b 0 (n - 1);
superset_vec_ge_lemma #(n - 1) (slice a 0 (n - 1)) (slice b 0 (n - 1)) | false |
FStar.UInt.fst | FStar.UInt.logor_self | val logor_self: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logor #n a a = a)) | val logor_self: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logor #n a a = a)) | let logor_self #n a = nth_lemma #n (logor #n a a) a | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 235,
"start_col": 0,
"start_line": 235
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> FStar.Pervasives.Lemma (ensures FStar.UInt.logor a a = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logor",
"Prims.unit"
] | [] | true | false | true | false | false | let logor_self #n a =
| nth_lemma #n (logor #n a a) a | false |
FStar.UInt.fst | FStar.UInt.logor_associative | val logor_associative: #n:pos -> a:uint_t n -> b:uint_t n -> c:uint_t n ->
Lemma (requires True)
(ensures (logor #n (logor #n a b) c = logor #n a (logor #n b c))) | val logor_associative: #n:pos -> a:uint_t n -> b:uint_t n -> c:uint_t n ->
Lemma (requires True)
(ensures (logor #n (logor #n a b) c = logor #n a (logor #n b c))) | let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 101,
"end_line": 233,
"start_col": 0,
"start_line": 233
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> c: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.logor (FStar.UInt.logor a b) c = FStar.UInt.logor a (FStar.UInt.logor b c)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logor",
"Prims.unit"
] | [] | true | false | true | false | false | let logor_associative #n a b c =
| nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c)) | false |
FStar.UInt.fst | FStar.UInt.logor_lemma_2 | val logor_lemma_2: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logor #n a (ones n) = ones n)) | val logor_lemma_2: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (logor #n a (ones n) = ones n)) | let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 239,
"start_col": 0,
"start_line": 239
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logor a (FStar.UInt.ones n) = FStar.UInt.ones n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.logor",
"FStar.UInt.ones",
"Prims.unit"
] | [] | true | false | true | false | false | let logor_lemma_2 #n a =
| nth_lemma (logor #n a (ones n)) (ones n) | false |
FStar.UInt.fst | FStar.UInt.lognot_self | val lognot_self: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (lognot #n (lognot #n a) = a)) | val lognot_self: #n:pos -> a:uint_t n ->
Lemma (requires True) (ensures (lognot #n (lognot #n a) = a)) | let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 253,
"start_col": 0,
"start_line": 253
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.lognot (FStar.UInt.lognot a) = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.nth_lemma",
"FStar.UInt.lognot",
"Prims.unit"
] | [] | true | false | true | false | false | let lognot_self #n a =
| nth_lemma (lognot #n (lognot #n a)) a | false |
FStar.UInt.fst | FStar.UInt.logor_ge | val logor_ge: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True)
(ensures (logor a b) >= a /\ (logor a b) >= b) | val logor_ge: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (requires True)
(ensures (logor a b) >= a /\ (logor a b) >= b) | let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 251,
"start_col": 0,
"start_line": 246
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.logor a b >= a /\ FStar.UInt.logor a b >= b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.superset_vec_ge_lemma",
"Prims.unit",
"FStar.BitVector.bv_t",
"FStar.UInt.to_vec",
"FStar.UInt.logor"
] | [] | true | false | true | false | false | let logor_ge #n a b =
| let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb | false |
FStar.UInt.fst | FStar.UInt.lognot_lemma_1 | val lognot_lemma_1: #n:pos ->
Lemma (requires True) (ensures (lognot #n (zero n) = ones n)) | val lognot_lemma_1: #n:pos ->
Lemma (requires True) (ensures (lognot #n (zero n) = ones n)) | let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 255,
"start_col": 0,
"start_line": 255
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | FStar.Pervasives.Lemma (ensures FStar.UInt.lognot (FStar.UInt.zero n) = FStar.UInt.ones n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.nth_lemma",
"FStar.UInt.lognot",
"FStar.UInt.zero",
"FStar.UInt.ones",
"Prims.unit"
] | [] | true | false | true | false | false | let lognot_lemma_1 #n =
| nth_lemma (lognot #n (zero n)) (ones n) | false |
FStar.UInt.fst | FStar.UInt.to_vec_mod_pow2 | val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)] | val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)] | let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 7,
"end_line": 273,
"start_col": 0,
"start_line": 261
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> m: Prims.pos -> i: Prims.nat{n - m <= i /\ i < n}
-> FStar.Pervasives.Lemma (requires a % Prims.pow2 m == 0)
(ensures FStar.Seq.Base.index (FStar.UInt.to_vec a) i == false)
[SMTPat (FStar.Seq.Base.index (FStar.UInt.to_vec a) i); SMTPat (Prims.pow2 m)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.UInt.uint_t",
"Prims.pos",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"FStar.Math.Lemmas.mod_mult_exact",
"Prims.pow2",
"Prims.unit",
"FStar.Seq.Base.lemma_index_app2",
"Prims.bool",
"FStar.UInt.to_vec",
"Prims.op_Division",
"FStar.Seq.Base.create",
"Prims.op_Modulus",
"FStar.UInt.to_vec_mod_pow2",
"FStar.Math.Lemmas.mod_pow2_div2",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.lemma_index_app1"
] | [
"recursion"
] | false | false | true | false | false | let rec to_vec_mod_pow2 #n a m i =
| if i = n - 1
then
(lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1)))
else
(lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i) | false |
FStar.UInt.fst | FStar.UInt.to_vec_lt_pow2 | val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)] | val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)] | let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 289,
"start_col": 0,
"start_line": 279
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> m: Prims.nat -> i: Prims.nat{i < n - m}
-> FStar.Pervasives.Lemma (requires a < Prims.pow2 m)
(ensures FStar.Seq.Base.index (FStar.UInt.to_vec a) i == false)
[SMTPat (FStar.Seq.Base.index (FStar.UInt.to_vec a) i); SMTPat (Prims.pow2 m)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Prims._assert",
"Prims.eq2",
"FStar.UInt.zero",
"FStar.UInt.to_vec_lt_pow2",
"Prims.op_Division",
"Prims.unit",
"FStar.Seq.Base.index",
"FStar.UInt.to_vec",
"FStar.Seq.Base.lemma_index_app1",
"FStar.Seq.Base.create",
"Prims.op_Modulus"
] | [
"recursion"
] | false | false | true | false | false | let rec to_vec_lt_pow2 #n a m i =
| if n = 0
then ()
else
if m = 0
then assert (a == zero n)
else
(lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i) | false |
FStar.UInt.fst | FStar.UInt.logor_disjoint | val logor_disjoint: #n:pos -> a:uint_t n -> b:uint_t n -> m:pos{m < n} ->
Lemma (requires (a % pow2 m == 0 /\ b < pow2 m))
(ensures (logor #n a b == a + b)) | val logor_disjoint: #n:pos -> a:uint_t n -> b:uint_t n -> m:pos{m < n} ->
Lemma (requires (a % pow2 m == 0 /\ b < pow2 m))
(ensures (logor #n a b == a + b)) | let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 319,
"start_col": 0,
"start_line": 302
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> m: Prims.pos{m < n}
-> FStar.Pervasives.Lemma (requires a % Prims.pow2 m == 0 /\ b < Prims.pow2 m)
(ensures FStar.UInt.logor a b == a + b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt.from_vec",
"FStar.Seq.Base.slice",
"Prims.bool",
"FStar.UInt.to_vec",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lemmas.small_modulo_lemma_1",
"Prims.pow2",
"FStar.UInt.slice_right_lemma",
"FStar.Mul.op_Star",
"FStar.Math.Lemmas.div_exact_r",
"FStar.UInt.slice_left_lemma",
"FStar.UInt.append_lemma",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.BitVector.logor_vec",
"FStar.Seq.Base.append",
"FStar.Seq.Properties.lemma_split",
"Prims.l_Forall",
"Prims.nat",
"FStar.Seq.Base.index",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_Modulus"
] | [] | false | false | true | false | false | let logor_disjoint #n a b m =
| assert (a % pow2 m == 0);
assert (forall (i: nat{n - m <= i /\ i < n}). {:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m);
assert (forall (i: nat{i < n - m}). {:pattern (index (to_vec b) i)} index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro (logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b) | false |
FStar.UInt.fst | FStar.UInt.shift_left_logand_lemma | val shift_left_logand_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_left #n (logand #n a b) s = logand #n (shift_left #n a s) (shift_left #n b s))) | val shift_left_logand_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_left #n (logand #n a b) s = logand #n (shift_left #n a s) (shift_left #n b s))) | let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 134,
"end_line": 341,
"start_col": 0,
"start_line": 341
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> s: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left (FStar.UInt.logand a b) s =
FStar.UInt.logand (FStar.UInt.shift_left a s) (FStar.UInt.shift_left b s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"FStar.UInt.nth_lemma",
"FStar.UInt.shift_left",
"FStar.UInt.logand",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_left_logand_lemma #n a b s =
| nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s)) | false |
FStar.UInt.fst | FStar.UInt.index_to_vec_ones | val index_to_vec_ones: #n:pos -> m:nat{m <= n} -> i:nat{i < n} ->
Lemma (requires True)
(ensures (pow2 m <= pow2 n /\
(i < n - m ==> index (to_vec #n (pow2 m - 1)) i == false) /\
(n - m <= i ==> index (to_vec #n (pow2 m - 1)) i == true)))
[SMTPat (index (to_vec #n (pow2 m - 1)) i)] | val index_to_vec_ones: #n:pos -> m:nat{m <= n} -> i:nat{i < n} ->
Lemma (requires True)
(ensures (pow2 m <= pow2 n /\
(i < n - m ==> index (to_vec #n (pow2 m - 1)) i == false) /\
(n - m <= i ==> index (to_vec #n (pow2 m - 1)) i == true)))
[SMTPat (index (to_vec #n (pow2 m - 1)) i)] | let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 299,
"start_col": 0,
"start_line": 293
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 2,
"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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Prims.nat{m <= n} -> i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
Prims.pow2 m <= Prims.pow2 n /\
(i < n - m ==> FStar.Seq.Base.index (FStar.UInt.to_vec (Prims.pow2 m - 1)) i == false) /\
(n - m <= i ==> FStar.Seq.Base.index (FStar.UInt.to_vec (Prims.pow2 m - 1)) i == true))
[SMTPat (FStar.Seq.Base.index (FStar.UInt.to_vec (Prims.pow2 m - 1)) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.one_to_vec_lemma",
"Prims.bool",
"Prims.l_or",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"FStar.UInt.ones_to_vec_lemma",
"Prims.op_Subtraction",
"FStar.UInt.index_to_vec_ones",
"Prims.unit",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.pow2"
] | [
"recursion"
] | false | false | true | false | false | let rec index_to_vec_ones #n m i =
| let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0
then one_to_vec_lemma #n i
else
if m = n
then ones_to_vec_lemma #n i
else if i = n - 1 then () else index_to_vec_ones #(n - 1) (m - 1) i | false |
FStar.UInt.fst | FStar.UInt.shift_right_logand_lemma | val shift_right_logand_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_right #n (logand #n a b) s = logand #n (shift_right #n a s) (shift_right #n b s))) | val shift_right_logand_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_right #n (logand #n a b) s = logand #n (shift_right #n a s) (shift_right #n b s))) | let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 138,
"end_line": 343,
"start_col": 0,
"start_line": 343
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> s: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_right (FStar.UInt.logand a b) s =
FStar.UInt.logand (FStar.UInt.shift_right a s) (FStar.UInt.shift_right b s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"FStar.UInt.nth_lemma",
"FStar.UInt.shift_right",
"FStar.UInt.logand",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_right_logand_lemma #n a b s =
| nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s)) | false |
FStar.UInt.fst | FStar.UInt.shift_left_logor_lemma | val shift_left_logor_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_left #n (logor #n a b) s = logor #n (shift_left #n a s) (shift_left #n b s))) | val shift_left_logor_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_left #n (logor #n a b) s = logor #n (shift_left #n a s) (shift_left #n b s))) | let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 131,
"end_line": 349,
"start_col": 0,
"start_line": 349
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> s: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left (FStar.UInt.logor a b) s =
FStar.UInt.logor (FStar.UInt.shift_left a s) (FStar.UInt.shift_left b s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"FStar.UInt.nth_lemma",
"FStar.UInt.shift_left",
"FStar.UInt.logor",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_left_logor_lemma #n a b s =
| nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s)) | false |
FStar.UInt.fst | FStar.UInt.shift_left_logxor_lemma | val shift_left_logxor_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_left #n (logxor #n a b) s = logxor #n (shift_left #n a s) (shift_left #n b s))) | val shift_left_logxor_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_left #n (logxor #n a b) s = logxor #n (shift_left #n a s) (shift_left #n b s))) | let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 134,
"end_line": 345,
"start_col": 0,
"start_line": 345
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> s: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_left (FStar.UInt.logxor a b) s =
FStar.UInt.logxor (FStar.UInt.shift_left a s) (FStar.UInt.shift_left b s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"FStar.UInt.nth_lemma",
"FStar.UInt.shift_left",
"FStar.UInt.logxor",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_left_logxor_lemma #n a b s =
| nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s)) | false |
FStar.UInt.fst | FStar.UInt.shift_right_logxor_lemma | val shift_right_logxor_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_right #n (logxor #n a b) s = logxor #n (shift_right #n a s) (shift_right #n b s))) | val shift_right_logxor_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_right #n (logxor #n a b) s = logxor #n (shift_right #n a s) (shift_right #n b s))) | let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 138,
"end_line": 347,
"start_col": 0,
"start_line": 347
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> s: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_right (FStar.UInt.logxor a b) s =
FStar.UInt.logxor (FStar.UInt.shift_right a s) (FStar.UInt.shift_right b s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"FStar.UInt.nth_lemma",
"FStar.UInt.shift_right",
"FStar.UInt.logxor",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_right_logxor_lemma #n a b s =
| nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s)) | false |
FStar.UInt.fst | FStar.UInt.shift_right_logor_lemma | val shift_right_logor_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_right #n (logor #n a b) s = logor #n (shift_right #n a s) (shift_right #n b s))) | val shift_right_logor_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> s:nat ->
Lemma (requires True)
(ensures (shift_right #n (logor #n a b) s = logor #n (shift_right #n a s) (shift_right #n b s))) | let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s)) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 135,
"end_line": 351,
"start_col": 0,
"start_line": 351
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> s: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.shift_right (FStar.UInt.logor a b) s =
FStar.UInt.logor (FStar.UInt.shift_right a s) (FStar.UInt.shift_right b s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"FStar.UInt.nth_lemma",
"FStar.UInt.shift_right",
"FStar.UInt.logor",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_right_logor_lemma #n a b s =
| nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s)) | false |
FStar.UInt.fst | FStar.UInt.shift_left_value_aux_1 | val shift_left_value_aux_1: #n:pos -> a:uint_t n -> s:nat{s >= n} ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) % pow2 n) | val shift_left_value_aux_1: #n:pos -> a:uint_t n -> s:nat{s >= n} ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) % pow2 n) | let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 76,
"end_line": 354,
"start_col": 0,
"start_line": 354
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> s: Prims.nat{s >= n}
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_left a s = a * Prims.pow2 s % Prims.pow2 n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_1",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_left_value_aux_1 #n a s =
| pow2_multiplication_modulo_lemma_1 a n s | false |
FStar.UInt.fst | FStar.UInt.shift_left_value_lemma | val shift_left_value_lemma: #n:pos -> a:uint_t n -> s:nat ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) % pow2 n)
[SMTPat (shift_left #n a s)] | val shift_left_value_lemma: #n:pos -> a:uint_t n -> s:nat ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) % pow2 n)
[SMTPat (shift_left #n a s)] | let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 368,
"start_col": 0,
"start_line": 365
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> s: Prims.nat
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_left a s = a * Prims.pow2 s % Prims.pow2 n)
[SMTPat (FStar.UInt.shift_left a s)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.shift_left_value_aux_1",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.shift_left_value_aux_2",
"FStar.UInt.shift_left_value_aux_3",
"Prims.unit"
] | [] | false | false | true | false | false | let shift_left_value_lemma #n a s =
| if s >= n
then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a else shift_left_value_aux_3 #n a s | false |
FStar.UInt.fst | FStar.UInt.logand_mask | val logand_mask: #n:pos -> a:uint_t n -> m:pos{m < n} ->
Lemma (pow2 m < pow2 n /\ logand #n a (pow2 m - 1) == a % pow2 m) | val logand_mask: #n:pos -> a:uint_t n -> m:pos{m < n} ->
Lemma (pow2 m < pow2 n /\ logand #n a (pow2 m - 1) == a % pow2 m) | let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 331,
"start_col": 0,
"start_line": 321
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> m: Prims.pos{m < n}
-> FStar.Pervasives.Lemma
(ensures
Prims.pow2 m < Prims.pow2 n /\ FStar.UInt.logand a (Prims.pow2 m - 1) == a % Prims.pow2 m) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"FStar.UInt.from_vec",
"FStar.Seq.Base.slice",
"Prims.bool",
"FStar.UInt.to_vec",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"Prims.pow2",
"Prims.unit",
"FStar.UInt.slice_right_lemma",
"FStar.BitVector.zero_vec",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"FStar.UInt.append_lemma",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.BitVector.logand_vec",
"FStar.Seq.Base.append",
"FStar.Seq.Properties.lemma_split",
"FStar.Math.Lemmas.pow2_lt_compat"
] | [] | true | false | true | false | false | let logand_mask #n a m =
| pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro (logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m) | false |
FStar.UInt.fst | FStar.UInt.shift_left_value_aux_2 | val shift_left_value_aux_2: #n:pos -> a:uint_t n ->
Lemma (requires True)
(ensures shift_left #n a 0 = (a * pow2 0) % pow2 n) | val shift_left_value_aux_2: #n:pos -> a:uint_t n ->
Lemma (requires True)
(ensures shift_left #n a 0 = (a * pow2 0) % pow2 n) | let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 358,
"start_col": 0,
"start_line": 356
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_left a 0 = a * Prims.pow2 0 % Prims.pow2 n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Math.Lemmas.small_modulo_lemma_1",
"Prims.pow2",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star"
] | [] | true | false | true | false | false | let shift_left_value_aux_2 #n a =
| assert_norm (a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n) | false |
FStar.UInt.fst | FStar.UInt.shift_right_value_aux_2 | val shift_right_value_aux_2: #n:pos -> a:uint_t n ->
Lemma (requires True)
(ensures shift_right #n a 0 = a / pow2 0) | val shift_right_value_aux_2: #n:pos -> a:uint_t n ->
Lemma (requires True)
(ensures shift_right #n a 0 = a / pow2 0) | let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 374,
"start_col": 0,
"start_line": 374
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_right a 0 = a / Prims.pow2 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_right_value_aux_2 #n a =
| assert_norm (pow2 0 == 1) | false |
FStar.UInt.fst | FStar.UInt.shift_right_value_lemma | val shift_right_value_lemma: #n:pos -> a:uint_t n -> s:nat ->
Lemma (requires True)
(ensures shift_right #n a s = a / pow2 s)
[SMTPat (shift_right #n a s)] | val shift_right_value_lemma: #n:pos -> a:uint_t n -> s:nat ->
Lemma (requires True)
(ensures shift_right #n a s = a / pow2 s)
[SMTPat (shift_right #n a s)] | let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 385,
"start_col": 0,
"start_line": 382
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> s: Prims.nat
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_right a s = a / Prims.pow2 s)
[SMTPat (FStar.UInt.shift_right a s)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.shift_right_value_aux_1",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.shift_right_value_aux_2",
"FStar.UInt.shift_right_value_aux_3",
"Prims.unit"
] | [] | false | false | true | false | false | let shift_right_value_lemma #n a s =
| if s >= n
then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a else shift_right_value_aux_3 #n a s | false |
FStar.UInt.fst | FStar.UInt.shift_right_value_aux_1 | val shift_right_value_aux_1: #n:pos -> a:uint_t n -> s:nat{s >= n} ->
Lemma (requires True)
(ensures shift_right #n a s = a / pow2 s) | val shift_right_value_aux_1: #n:pos -> a:uint_t n -> s:nat{s >= n} ->
Lemma (requires True)
(ensures shift_right #n a s = a / pow2 s) | let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 372,
"start_col": 0,
"start_line": 370
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> s: Prims.nat{s >= n}
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_right a s = a / Prims.pow2 s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Math.Lemmas.small_division_lemma_1",
"Prims.pow2",
"Prims.unit",
"FStar.Math.Lemmas.pow2_le_compat"
] | [] | true | false | true | false | false | let shift_right_value_aux_1 #n a s =
| pow2_le_compat s n;
small_division_lemma_1 a (pow2 s) | false |
FStar.UInt.fst | FStar.UInt.lemma_minus_zero | val lemma_minus_zero: #n:pos -> a:uint_t n ->
Lemma (minus a = 0 ==> a = 0) | val lemma_minus_zero: #n:pos -> a:uint_t n ->
Lemma (minus a = 0 ==> a = 0) | let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 400,
"start_col": 0,
"start_line": 393
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> FStar.Pervasives.Lemma (ensures FStar.UInt.minus a = 0 ==> a = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.minus",
"FStar.UInt.logxor_lemma_2",
"FStar.UInt.ones",
"Prims.unit",
"FStar.UInt.logxor_self",
"FStar.UInt.lognot_self",
"FStar.UInt.plus_one_mod",
"Prims.pow2",
"FStar.UInt.lognot",
"Prims.bool"
] | [] | false | false | true | false | false | let lemma_minus_zero #n a =
| if minus a = 0
then
(plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)) | false |
FStar.UInt.fst | FStar.UInt.lemma_add_sub_cancel | val lemma_add_sub_cancel: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (add_mod (sub_mod a b) b = a) | val lemma_add_sub_cancel: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (add_mod (sub_mod a b) b = a) | let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 428,
"start_col": 0,
"start_line": 416
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.add_mod (FStar.UInt.sub_mod a b) b = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Addition",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"FStar.UInt.add_mod",
"FStar.UInt.sub_mod",
"FStar.UInt.lemma_uint_mod",
"Prims.pow2"
] | [] | true | false | true | false | false | let lemma_add_sub_cancel #n a b =
| let ab = (a - b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a - b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a - b) b p;
assert (((a - b) + b) % p = (((a - b) % p) + b) % p);
assert (a % p = (((a - b) % p) + b) % p) | false |
FStar.UInt.fst | FStar.UInt.lemma_msb_gte | val lemma_msb_gte: #n:pos{n > 1} -> a:uint_t n -> b:uint_t n ->
Lemma ((a >= b && not (msb a)) ==> not (msb b)) | val lemma_msb_gte: #n:pos{n > 1} -> a:uint_t n -> b:uint_t n ->
Lemma ((a >= b && not (msb a)) ==> not (msb b)) | let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1 | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 405,
"start_col": 0,
"start_line": 403
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures a >= b && Prims.op_Negation (FStar.UInt.msb a) ==> Prims.op_Negation (FStar.UInt.msb b)
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.UInt.uint_t",
"FStar.UInt.from_vec_propriety",
"FStar.UInt.to_vec",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_msb_gte #n a b =
| from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1 | false |
FStar.UInt.fst | FStar.UInt.lemma_mod_sub_distr_l | val lemma_mod_sub_distr_l: a:int -> b:int -> p:pos ->
Lemma ((a - b) % p = ((a % p) - b) % p) | val lemma_mod_sub_distr_l: a:int -> b:int -> p:pos ->
Lemma ((a - b) % p = ((a % p) - b) % p) | let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 433,
"start_col": 0,
"start_line": 430
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: Prims.int -> b: Prims.int -> p: Prims.pos
-> FStar.Pervasives.Lemma (ensures (a - b) % p = (a % p - b) % p) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Prims.pos",
"FStar.Math.Lemmas.lemma_mod_plus",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_spec2",
"Prims.op_Division"
] | [] | true | false | true | false | false | let lemma_mod_sub_distr_l a b p =
| let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p | false |
FStar.UInt.fst | FStar.UInt.shift_left_value_aux_3 | val shift_left_value_aux_3: #n:pos -> a:uint_t n -> s:pos{s < n} ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) % pow2 n) | val shift_left_value_aux_3: #n:pos -> a:uint_t n -> s:pos{s < n} ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) % pow2 n) | let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 363,
"start_col": 0,
"start_line": 360
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> s: Prims.pos{s < n}
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_left a s = a * Prims.pow2 s % Prims.pow2 n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2",
"Prims.unit",
"FStar.UInt.slice_right_lemma",
"FStar.UInt.to_vec",
"Prims.op_Subtraction",
"FStar.UInt.append_lemma",
"FStar.Seq.Base.slice",
"Prims.bool",
"FStar.BitVector.zero_vec"
] | [] | true | false | true | false | false | let shift_left_value_aux_3 #n a s =
| append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s | false |
FStar.UInt.fst | FStar.UInt.lemma_sub_add_cancel | val lemma_sub_add_cancel: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (sub_mod (add_mod a b) b = a) | val lemma_sub_add_cancel: #n:pos -> a:uint_t n -> b:uint_t n ->
Lemma (sub_mod (add_mod a b) b = a) | let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 442,
"start_col": 0,
"start_line": 435
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.sub_mod (FStar.UInt.add_mod a b) b = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.lemma_mod_sub_distr_l",
"Prims.op_Addition",
"Prims.unit",
"FStar.UInt.lemma_uint_mod",
"Prims.pow2",
"FStar.UInt.sub_mod",
"FStar.UInt.add_mod",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Subtraction"
] | [] | true | false | true | false | false | let lemma_sub_add_cancel #n a b =
| let ab = (a + b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a + b) b p | false |
FStar.UInt.fst | FStar.UInt.lemma_zero_extend | val lemma_zero_extend: #n:pos -> a:uint_t n ->
Lemma (zero_extend a = a)
[SMTPat (zero_extend a)] | val lemma_zero_extend: #n:pos -> a:uint_t n ->
Lemma (zero_extend a = a)
[SMTPat (zero_extend a)] | let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 16,
"end_line": 452,
"start_col": 0,
"start_line": 444
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.zero_extend a = a)
[SMTPat (FStar.UInt.zero_extend a)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"Prims.op_Addition",
"Prims.unit",
"FStar.UInt.from_vec_propriety",
"FStar.UInt.from_vec",
"FStar.UInt.append_lemma",
"FStar.UInt.zero_extend",
"FStar.Seq.Base.seq",
"Prims.bool",
"FStar.Seq.Base.append",
"FStar.BitVector.bv_t",
"FStar.UInt.to_vec",
"FStar.Seq.Base.create"
] | [] | true | false | true | false | false | let lemma_zero_extend #n a =
| let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n + 1) eav 1;
assert (r = a) | false |
FStar.UInt.fst | FStar.UInt.lemma_msb_pow2 | val lemma_msb_pow2: #n:pos -> a:uint_t n ->
Lemma (msb a <==> a >= pow2 (n-1)) | val lemma_msb_pow2: #n:pos -> a:uint_t n ->
Lemma (msb a <==> a >= pow2 (n-1)) | let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1 | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 79,
"end_line": 387,
"start_col": 0,
"start_line": 387
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.msb a <==> a >= Prims.pow2 (n - 1)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.UInt.from_vec_propriety",
"FStar.UInt.to_vec",
"Prims.unit"
] | [] | false | false | true | false | false | let lemma_msb_pow2 #n a =
| if n = 1 then () else from_vec_propriety (to_vec a) 1 | false |
FStar.UInt.fst | FStar.UInt.lemma_lognot_value | val lemma_lognot_value: #n:pos -> a:uint_t n ->
Lemma (lognot #n a = sub_mod (sub_mod 0 a) 1) | val lemma_lognot_value: #n:pos -> a:uint_t n ->
Lemma (lognot #n a = sub_mod (sub_mod 0 a) 1) | let lemma_lognot_value #n a =
if a = 0 then lemma_lognot_value_zero a
else lemma_lognot_value_nonzero a | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 613,
"start_col": 0,
"start_line": 611
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a)
#push-options "--z3rlimit 40"
let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a)
#pop-options
#push-options "--fuel 1 --ifuel 0 --z3rlimit 40"
let lemma_lognot_zero_ext #n a =
let lhs = lognot #(n+1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n+1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n+1) eav = from_vec #n av);
assert (from_vec #(n+1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n+1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n+1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i:pos{i < n+1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs)
let lemma_lognot_one_ext #n a =
let lhs = lognot #(n+1) (one_extend a) in
let rhs = lognot #n a in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot #n a) in
let eav = Seq.append hd1 av in
append_lemma #1 #n hd1 av;
append_lemma #1 #n hd0 nav;
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd0 nav in
Seq.Base.lemma_eq_elim neav_l neav_r
#push-options "--z3rlimit 60"
let rec lemma_lognot_value_mod #n a =
if n = 1 then () else
begin
assert (-pow2 n <= (-(a+1)) && -(a+1) < 0);
let av = to_vec a in
let hd = from_vec #1 (Seq.slice (to_vec a) 0 1) in
let tl = from_vec #(n-1) (Seq.slice (to_vec a) 1 n) in
assert (hd = 0 || hd = 1);
let hdpow = op_Multiply hd (pow2 (n-1)) in
from_vec_propriety (to_vec a) 1;
assert (from_vec av = (op_Multiply
(from_vec #1 (Seq.slice av 0 1)) (pow2 (n-1))) +
(from_vec #(n-1) (Seq.slice av 1 n)));
let ntl = lognot tl in
lemma_lognot_value_mod #(n-1) tl;
assert (ntl = pow2 (n-1) - tl - 1);
assert (a = hdpow + tl);
assert (lognot a = lognot #n (hdpow + tl));
assert (tl < pow2 (n-1));
if hdpow = 0 then
begin
assert (lognot a = lognot #n tl);
lemma_lognot_zero_ext #(n-1) tl;
lemma_zero_extend tl
end
else
begin
lemma_lognot_one_ext #(n-1) tl;
lemma_one_extend tl
end
end
#pop-options
let lemma_lognot_value_zero #n a =
let p = pow2 n in
calc (==) {
sub_mod (sub_mod 0 a) 1;
== { }
sub_mod ((0 - a) % p) 1;
== { }
((0 - a) % p - 1) % p;
== { }
(0 % p - 1) % p;
== { modulo_lemma 0 p }
(0 - 1) % p;
== { lemma_mod_sub_0 p }
p - 1;
== { }
p - 0 - 1;
== { lemma_lognot_value_mod a }
lognot a;
}
#pop-options
#push-options "--z3rlimit 150"
private
val lemma_mod_variation: #n:pos -> a:uint_t n ->
Lemma (a <> 0 ==> ((-a) % pow2 n) - 1 % pow2 n = (((-a) % pow2 n) - 1) % pow2 n)
let lemma_mod_variation #n a = ()
#pop-options
let lemma_one_mod_pow2 #n = ()
#push-options "--z3rlimit 50"
private
val lemma_lognot_value_variation: #n:pos -> a:uint_t n{a <> 0} ->
Lemma (lognot a = (-a) % pow2 n - 1 % pow2 n)
let lemma_lognot_value_variation #n a =
let p = pow2 n in
calc (==) {
lognot a <: int;
== { lemma_lognot_value_mod a }
p - a - 1;
== { FStar.Math.Lemmas.modulo_lemma a p }
p - (a % p) - 1;
== { FStar.Math.Lemmas.modulo_lemma 1 p }
(p - (a % p)) - (1 % p);
== { FStar.Math.Lemmas.lemma_mod_sub_1 a p }
(-a) % p - 1 % p;
}
#pop-options
let lemma_lognot_value_nonzero #n a =
let p = pow2 n in
lemma_lognot_value_variation #n a;
assert (lognot a = (-a) % (pow2 n) - 1 % (pow2 n));
assert (sub_mod (sub_mod 0 a) 1 = (((0 - a) % p) - 1) % p);
lemma_mod_variation #n a;
assert (((-a) % p) - 1 % p = (((-a) % p) - 1) % p);
assert ((-a) % p - 1 % p = (((0 - a) % p) - 1) % p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.lognot a = FStar.UInt.sub_mod (FStar.UInt.sub_mod 0 a) 1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.lemma_lognot_value_zero",
"Prims.bool",
"FStar.UInt.lemma_lognot_value_nonzero",
"Prims.unit"
] | [] | false | false | true | false | false | let lemma_lognot_value #n a =
| if a = 0 then lemma_lognot_value_zero a else lemma_lognot_value_nonzero a | false |
FStar.UInt.fst | FStar.UInt.lemma_lognot_value_variation | val lemma_lognot_value_variation: #n:pos -> a:uint_t n{a <> 0} ->
Lemma (lognot a = (-a) % pow2 n - 1 % pow2 n) | val lemma_lognot_value_variation: #n:pos -> a:uint_t n{a <> 0} ->
Lemma (lognot a = (-a) % pow2 n - 1 % pow2 n) | let lemma_lognot_value_variation #n a =
let p = pow2 n in
calc (==) {
lognot a <: int;
== { lemma_lognot_value_mod a }
p - a - 1;
== { FStar.Math.Lemmas.modulo_lemma a p }
p - (a % p) - 1;
== { FStar.Math.Lemmas.modulo_lemma 1 p }
(p - (a % p)) - (1 % p);
== { FStar.Math.Lemmas.lemma_mod_sub_1 a p }
(-a) % p - 1 % p;
} | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 599,
"start_col": 0,
"start_line": 587
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a)
#push-options "--z3rlimit 40"
let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a)
#pop-options
#push-options "--fuel 1 --ifuel 0 --z3rlimit 40"
let lemma_lognot_zero_ext #n a =
let lhs = lognot #(n+1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n+1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n+1) eav = from_vec #n av);
assert (from_vec #(n+1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n+1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n+1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i:pos{i < n+1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs)
let lemma_lognot_one_ext #n a =
let lhs = lognot #(n+1) (one_extend a) in
let rhs = lognot #n a in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot #n a) in
let eav = Seq.append hd1 av in
append_lemma #1 #n hd1 av;
append_lemma #1 #n hd0 nav;
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd0 nav in
Seq.Base.lemma_eq_elim neav_l neav_r
#push-options "--z3rlimit 60"
let rec lemma_lognot_value_mod #n a =
if n = 1 then () else
begin
assert (-pow2 n <= (-(a+1)) && -(a+1) < 0);
let av = to_vec a in
let hd = from_vec #1 (Seq.slice (to_vec a) 0 1) in
let tl = from_vec #(n-1) (Seq.slice (to_vec a) 1 n) in
assert (hd = 0 || hd = 1);
let hdpow = op_Multiply hd (pow2 (n-1)) in
from_vec_propriety (to_vec a) 1;
assert (from_vec av = (op_Multiply
(from_vec #1 (Seq.slice av 0 1)) (pow2 (n-1))) +
(from_vec #(n-1) (Seq.slice av 1 n)));
let ntl = lognot tl in
lemma_lognot_value_mod #(n-1) tl;
assert (ntl = pow2 (n-1) - tl - 1);
assert (a = hdpow + tl);
assert (lognot a = lognot #n (hdpow + tl));
assert (tl < pow2 (n-1));
if hdpow = 0 then
begin
assert (lognot a = lognot #n tl);
lemma_lognot_zero_ext #(n-1) tl;
lemma_zero_extend tl
end
else
begin
lemma_lognot_one_ext #(n-1) tl;
lemma_one_extend tl
end
end
#pop-options
let lemma_lognot_value_zero #n a =
let p = pow2 n in
calc (==) {
sub_mod (sub_mod 0 a) 1;
== { }
sub_mod ((0 - a) % p) 1;
== { }
((0 - a) % p - 1) % p;
== { }
(0 % p - 1) % p;
== { modulo_lemma 0 p }
(0 - 1) % p;
== { lemma_mod_sub_0 p }
p - 1;
== { }
p - 0 - 1;
== { lemma_lognot_value_mod a }
lognot a;
}
#pop-options
#push-options "--z3rlimit 150"
private
val lemma_mod_variation: #n:pos -> a:uint_t n ->
Lemma (a <> 0 ==> ((-a) % pow2 n) - 1 % pow2 n = (((-a) % pow2 n) - 1) % pow2 n)
let lemma_mod_variation #n a = ()
#pop-options
let lemma_one_mod_pow2 #n = ()
#push-options "--z3rlimit 50"
private
val lemma_lognot_value_variation: #n:pos -> a:uint_t n{a <> 0} -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n {a <> 0}
-> FStar.Pervasives.Lemma (ensures FStar.UInt.lognot a = (- a) % Prims.pow2 n - 1 % Prims.pow2 n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"FStar.Calc.calc_finish",
"Prims.eq2",
"FStar.UInt.lognot",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"Prims.op_Minus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.UInt.lemma_lognot_value_mod",
"Prims.squash",
"FStar.Math.Lemmas.modulo_lemma",
"FStar.Math.Lemmas.lemma_mod_sub_1",
"Prims.pow2"
] | [] | false | false | true | false | false | let lemma_lognot_value_variation #n a =
| let p = pow2 n in
calc ( == ) {
lognot a <: int;
( == ) { lemma_lognot_value_mod a }
p - a - 1;
( == ) { FStar.Math.Lemmas.modulo_lemma a p }
p - (a % p) - 1;
( == ) { FStar.Math.Lemmas.modulo_lemma 1 p }
(p - (a % p)) - (1 % p);
( == ) { FStar.Math.Lemmas.lemma_mod_sub_1 a p }
(- a) % p - 1 % p;
} | false |
FStar.UInt.fst | FStar.UInt.lemma_minus_eq_zero_sub | val lemma_minus_eq_zero_sub: #n:pos -> a:uint_t n ->
Lemma (minus #n a = sub_mod #n 0 a) | val lemma_minus_eq_zero_sub: #n:pos -> a:uint_t n ->
Lemma (minus #n a = sub_mod #n 0 a) | let lemma_minus_eq_zero_sub #n a =
let na = lognot a in
let ma = minus a in
assert (sub_mod ma 1 = sub_mod (add_mod na 1) 1);
lemma_sub_add_cancel na 1;
assert (sub_mod ma 1 = na);
lemma_lognot_value #n a;
assert (na = sub_mod (sub_mod 0 a) 1);
assert (ma = add_mod (sub_mod (sub_mod 0 a) 1) 1);
lemma_add_sub_cancel (sub_mod 0 a) 1 | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 624,
"start_col": 0,
"start_line": 615
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a)
#push-options "--z3rlimit 40"
let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a)
#pop-options
#push-options "--fuel 1 --ifuel 0 --z3rlimit 40"
let lemma_lognot_zero_ext #n a =
let lhs = lognot #(n+1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n+1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n+1) eav = from_vec #n av);
assert (from_vec #(n+1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n+1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n+1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i:pos{i < n+1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs)
let lemma_lognot_one_ext #n a =
let lhs = lognot #(n+1) (one_extend a) in
let rhs = lognot #n a in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot #n a) in
let eav = Seq.append hd1 av in
append_lemma #1 #n hd1 av;
append_lemma #1 #n hd0 nav;
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd0 nav in
Seq.Base.lemma_eq_elim neav_l neav_r
#push-options "--z3rlimit 60"
let rec lemma_lognot_value_mod #n a =
if n = 1 then () else
begin
assert (-pow2 n <= (-(a+1)) && -(a+1) < 0);
let av = to_vec a in
let hd = from_vec #1 (Seq.slice (to_vec a) 0 1) in
let tl = from_vec #(n-1) (Seq.slice (to_vec a) 1 n) in
assert (hd = 0 || hd = 1);
let hdpow = op_Multiply hd (pow2 (n-1)) in
from_vec_propriety (to_vec a) 1;
assert (from_vec av = (op_Multiply
(from_vec #1 (Seq.slice av 0 1)) (pow2 (n-1))) +
(from_vec #(n-1) (Seq.slice av 1 n)));
let ntl = lognot tl in
lemma_lognot_value_mod #(n-1) tl;
assert (ntl = pow2 (n-1) - tl - 1);
assert (a = hdpow + tl);
assert (lognot a = lognot #n (hdpow + tl));
assert (tl < pow2 (n-1));
if hdpow = 0 then
begin
assert (lognot a = lognot #n tl);
lemma_lognot_zero_ext #(n-1) tl;
lemma_zero_extend tl
end
else
begin
lemma_lognot_one_ext #(n-1) tl;
lemma_one_extend tl
end
end
#pop-options
let lemma_lognot_value_zero #n a =
let p = pow2 n in
calc (==) {
sub_mod (sub_mod 0 a) 1;
== { }
sub_mod ((0 - a) % p) 1;
== { }
((0 - a) % p - 1) % p;
== { }
(0 % p - 1) % p;
== { modulo_lemma 0 p }
(0 - 1) % p;
== { lemma_mod_sub_0 p }
p - 1;
== { }
p - 0 - 1;
== { lemma_lognot_value_mod a }
lognot a;
}
#pop-options
#push-options "--z3rlimit 150"
private
val lemma_mod_variation: #n:pos -> a:uint_t n ->
Lemma (a <> 0 ==> ((-a) % pow2 n) - 1 % pow2 n = (((-a) % pow2 n) - 1) % pow2 n)
let lemma_mod_variation #n a = ()
#pop-options
let lemma_one_mod_pow2 #n = ()
#push-options "--z3rlimit 50"
private
val lemma_lognot_value_variation: #n:pos -> a:uint_t n{a <> 0} ->
Lemma (lognot a = (-a) % pow2 n - 1 % pow2 n)
let lemma_lognot_value_variation #n a =
let p = pow2 n in
calc (==) {
lognot a <: int;
== { lemma_lognot_value_mod a }
p - a - 1;
== { FStar.Math.Lemmas.modulo_lemma a p }
p - (a % p) - 1;
== { FStar.Math.Lemmas.modulo_lemma 1 p }
(p - (a % p)) - (1 % p);
== { FStar.Math.Lemmas.lemma_mod_sub_1 a p }
(-a) % p - 1 % p;
}
#pop-options
let lemma_lognot_value_nonzero #n a =
let p = pow2 n in
lemma_lognot_value_variation #n a;
assert (lognot a = (-a) % (pow2 n) - 1 % (pow2 n));
assert (sub_mod (sub_mod 0 a) 1 = (((0 - a) % p) - 1) % p);
lemma_mod_variation #n a;
assert (((-a) % p) - 1 % p = (((-a) % p) - 1) % p);
assert ((-a) % p - 1 % p = (((0 - a) % p) - 1) % p)
let lemma_lognot_value #n a =
if a = 0 then lemma_lognot_value_zero a
else lemma_lognot_value_nonzero a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.minus a = FStar.UInt.sub_mod 0 a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.UInt.lemma_add_sub_cancel",
"FStar.UInt.sub_mod",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"FStar.UInt.add_mod",
"FStar.UInt.lemma_lognot_value",
"FStar.UInt.lemma_sub_add_cancel",
"FStar.UInt.minus",
"FStar.UInt.lognot"
] | [] | true | false | true | false | false | let lemma_minus_eq_zero_sub #n a =
| let na = lognot a in
let ma = minus a in
assert (sub_mod ma 1 = sub_mod (add_mod na 1) 1);
lemma_sub_add_cancel na 1;
assert (sub_mod ma 1 = na);
lemma_lognot_value #n a;
assert (na = sub_mod (sub_mod 0 a) 1);
assert (ma = add_mod (sub_mod (sub_mod 0 a) 1) 1);
lemma_add_sub_cancel (sub_mod 0 a) 1 | false |
Trace.fst | Trace.tick | val tick (nm: fv) : fv | val tick (nm: fv) : fv | let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns) | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 66,
"start_col": 0,
"start_line": 64
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | nm: FStar.Stubs.Reflection.Types.fv -> FStar.Stubs.Reflection.Types.fv | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"Trace.tick_last",
"FStar.Stubs.Reflection.Types.name",
"FStar.Stubs.Reflection.V2.Builtins.inspect_fv"
] | [] | false | false | false | true | false | let tick (nm: fv) : fv =
| let ns = inspect_fv nm in
pack_fv (tick_last ns) | false |
Trace.fst | Trace.cons_fst | val cons_fst (x: 'a) (p: (list 'a * 'b)) : list 'a * 'b | val cons_fst (x: 'a) (p: (list 'a * 'b)) : list 'a * 'b | let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z) | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 69,
"start_col": 0,
"start_line": 68
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | x: 'a -> p: (Prims.list 'a * 'b) -> Prims.list 'a * 'b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Prims.list",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Cons"
] | [] | false | false | false | true | false | let cons_fst (x: 'a) (p: list 'a * 'b) : list 'a * 'b =
| let y, z = p in
(x :: y, z) | false |
Trace.fst | Trace.cons_fst_qn | val cons_fst_qn : Prims.list Prims.string | let cons_fst_qn = ["Trace"; "cons_fst"] | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 71,
"start_col": 0,
"start_line": 71
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | Prims.list Prims.string | Prims.Tot | [
"total"
] | [] | [
"Prims.Cons",
"Prims.string",
"Prims.Nil"
] | [] | false | false | false | true | false | let cons_fst_qn =
| ["Trace"; "cons_fst"] | false |
|
Steel.ST.SeqMatch.fst | Steel.ST.SeqMatch.seq_seq_match_item_match_option_elim | val seq_seq_match_item_match_option_elim
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit
opened
(seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
(fun _ -> seq_seq_match p s1 s2 i j) | val seq_seq_match_item_match_option_elim
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit
opened
(seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
(fun _ -> seq_seq_match p s1 s2 i j) | let seq_seq_match_item_match_option_elim
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit opened
(seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
(fun _ -> seq_seq_match p s1 s2 i j)
= on_range_weaken
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
(seq_seq_match_item p s1 s2)
i j
(fun k ->
rewrite
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)
(seq_seq_match_item p s1 s2 k)
) | {
"file_name": "lib/steel/Steel.ST.SeqMatch.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 629,
"start_col": 0,
"start_line": 611
} | module Steel.ST.SeqMatch
include Steel.ST.OnRange
open Steel.ST.GenElim
module Seq = FStar.Seq
module SZ = FStar.SizeT
(* `seq_list_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a list of high-level
values. `seq_list_match` is carefully designed to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values. *)
[@@__reduce__]
let seq_list_match_nil0
(#t: Type)
(c: Seq.seq t)
: Tot vprop
= pure (c `Seq.equal` Seq.empty)
[@@__reduce__]
let seq_list_match_cons0
(#t #t': Type)
(c: Seq.seq t)
(l: list t' { Cons? l })
(item_match: (t -> (v': t' { v' << l }) -> vprop))
(seq_list_match: (Seq.seq t -> (v': list t') -> (raw_data_item_match: (t -> (v'': t' { v'' << v' }) -> vprop) { v' << l }) ->
vprop))
: Tot vprop
= exists_ (fun (c1: t) -> exists_ (fun (c2: Seq.seq t) ->
item_match c1 (List.Tot.hd l) `star`
seq_list_match c2 (List.Tot.tl l) item_match `star`
pure (c `Seq.equal` Seq.cons c1 c2)
))
let rec seq_list_match
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Tot vprop
(decreases v)
= if Nil? v
then seq_list_match_nil0 c
else seq_list_match_cons0 c v item_match seq_list_match
let seq_list_match_cons_eq
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Lemma
(requires (Cons? v))
(ensures (
seq_list_match c v item_match ==
seq_list_match_cons0 c v item_match seq_list_match
))
= let a :: q = v in
assert_norm (seq_list_match c (a :: q) item_match ==
seq_list_match_cons0 c (a :: q) item_match seq_list_match
)
let seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhost unit opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\
Nil? v)
(fun _ -> True)
= noop ();
rewrite
(seq_list_match_nil0 c)
(seq_list_match c v item_match)
let list_cons_precedes
(#t: Type)
(a: t)
(q: list t)
: Lemma
((a << a :: q) /\ (q << a :: q))
[SMTPat (a :: q)]
= assert (List.Tot.hd (a :: q) << (a :: q));
assert (List.Tot.tl (a :: q) << (a :: q))
let seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a' : t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << a' :: v }) -> vprop))
: STGhostT unit opened
(item_match a a' `star` seq_list_match c v item_match)
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match)
= seq_list_match_cons_eq (Seq.cons a c) (a' :: v) item_match;
noop ();
rewrite
(seq_list_match_cons0 (Seq.cons a c) (a' :: v) item_match seq_list_match)
(seq_list_match (Seq.cons a c) (a' :: v) item_match)
let seq_list_match_cons_elim
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t' { Cons? v \/ Seq.length c > 0 })
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhostT (squash (Cons? v /\ Seq.length c > 0)) opened
(seq_list_match c v item_match)
(fun _ -> item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
= if Nil? v
then begin
rewrite
(seq_list_match c v item_match)
(seq_list_match_nil0 c);
let _ = gen_elim () in
assert False;
rewrite // by contradiction
emp
(item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
end else begin
seq_list_match_cons_eq c v item_match;
noop ();
rewrite
(seq_list_match c v item_match)
(seq_list_match_cons0 c v item_match seq_list_match);
let _ = gen_elim () in
let prf : squash (Cons? v /\ Seq.length c > 0) = () in
let c1 = vpattern (fun c1 -> item_match c1 (List.Tot.hd v)) in
let c2 = vpattern (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) in
Seq.lemma_cons_inj c1 (Seq.head c) c2 (Seq.tail c);
vpattern_rewrite (fun c1 -> item_match c1 (List.Tot.hd v)) (Seq.head c);
vpattern_rewrite (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) (Seq.tail c);
prf
end
// this one cannot be proven with seq_seq_match because of the << refinement in the type of item_match
let rec seq_list_match_weaken
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match1 item_match2: (t -> (v': t' { v' << v }) -> vprop))
(prf: (
(#opened: _) ->
(c': t) ->
(v': t' { v' << v }) ->
STGhostT unit opened
(item_match1 c' v')
(fun _ -> item_match2 c' v')
))
: STGhostT unit opened
(seq_list_match c v item_match1)
(fun _ -> seq_list_match c v item_match2)
(decreases v)
= if Nil? v
then
rewrite (seq_list_match c v item_match1) (seq_list_match c v item_match2)
else begin
let _ : squash (Cons? v) = () in
seq_list_match_cons_eq c v item_match1;
seq_list_match_cons_eq c v item_match2;
rewrite
(seq_list_match c v item_match1)
(seq_list_match_cons0 c v item_match1 seq_list_match);
let _ = gen_elim () in
prf _ _;
seq_list_match_weaken _ (List.Tot.tl v) item_match1 item_match2 prf;
rewrite
(seq_list_match_cons0 c v item_match2 seq_list_match)
(seq_list_match c v item_match2)
end
(* `seq_seq_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a sequence of high-level
values. Contrary to `seq_list_match`, `seq_seq_match` is not meant to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values, because no lemma ensures that `Seq.index s i << s` *)
let seq_seq_match_item
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i: nat)
: Tot vprop
= if i < Seq.length c && i < Seq.length l
then
p (Seq.index c i) (Seq.index l i)
else
pure (squash False)
let seq_seq_match_item_tail
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat)
(i: nat)
: Lemma
(requires (
i + delta <= Seq.length c /\
i + delta <= Seq.length l
))
(ensures (
seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i ==
seq_seq_match_item p c l (i + delta)
))
= ()
[@@__reduce__]
let seq_seq_match
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i j: nat)
: Tot vprop
= on_range (seq_seq_match_item p c l) i j
let seq_seq_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match p s1 s2 i j)
True
(fun _ -> i <= j /\ (i == j \/ (j <= Seq.length s1 /\ j <= Seq.length s2)))
= on_range_le (seq_seq_match_item p s1 s2) i j;
if i = j
then noop ()
else begin
let j' = j - 1 in
if j' < Seq.length s1 && j' < Seq.length s2
then noop ()
else begin
on_range_unsnoc
(seq_seq_match_item p s1 s2)
i j' j;
rewrite
(seq_seq_match_item p _ _ _)
(pure (squash False));
let _ = gen_elim () in
rewrite
(seq_seq_match p s1 s2 i j')
(seq_seq_match p s1 s2 i j) // by contradiction
end
end
let seq_seq_match_weaken
(#opened: _)
(#t1 #t2: Type)
(p p': t1 -> t2 -> vprop)
(w: ((x1: t1) -> (x2: t2) -> STGhostT unit opened
(p x1 x2) (fun _ -> p' x1 x2)
))
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p' c1' c2' i j)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
=
on_range_weaken
(seq_seq_match_item p c1 c2)
(seq_seq_match_item p' c1' c2')
i j
(fun k ->
rewrite (seq_seq_match_item p c1 c2 k) (p (Seq.index (Seq.slice c1 i j) (k - i)) (Seq.index (Seq.slice c2 i j) (k - i)));
w _ _;
rewrite (p' _ _) (seq_seq_match_item p' c1' c2' k)
)
let seq_seq_match_weaken_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p c1' c2' i j `star`
(seq_seq_match p c1' c2' i j `implies_` seq_seq_match p c1 c2 i j)
)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
= seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1 c1'
c2 c2'
i j;
intro_implies
(seq_seq_match p c1' c2' i j)
(seq_seq_match p c1 c2 i j)
emp
(fun _ ->
seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1' c1
c2' c2
i j
)
(* Going between `seq_list_match` and `seq_seq_match` *)
let seq_seq_match_tail_elim
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq (t2))
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i j: nat)
: STGhostT unit opened
(seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i j)
(fun _ -> seq_seq_match p c l (i + delta) (j + delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(seq_seq_match_item p c l)
delta
i j
(fun k ->
if k < Seq.length c - delta && k < Seq.length l - delta
then begin
seq_seq_match_item_tail p c l delta k;
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(seq_seq_match_item p c l (k + delta))
end else begin
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p c l (k + delta)) // by contradiction
end
)
(i + delta) (j + delta)
let seq_seq_match_tail_intro
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i: nat {
delta <= i
})
(j: nat)
: STGhostT (squash (i <= j)) opened
(seq_seq_match p c l i j)
(fun _ -> seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (i - delta) (j - delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p c l)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(0 - delta)
i j
(fun k ->
if k < Seq.length c && k < Seq.length l
then begin
seq_seq_match_item_tail p c l delta (k - delta);
rewrite
(seq_seq_match_item p c l k)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta)))
end else begin
rewrite
(seq_seq_match_item p c l k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta))) // by contradiction
end
)
(i - delta) (j - delta)
let rec seq_seq_match_seq_list_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p)
(Seq.length c == List.Tot.length l)
(fun _ -> True)
(decreases l)
= match l with
| [] ->
drop (seq_seq_match p _ _ _ _);
rewrite
(seq_list_match_nil0 c)
(seq_list_match c l p)
| a :: q ->
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
on_range_uncons
(seq_seq_match_item p _ _)
_ 1 _;
rewrite
(seq_seq_match_item p _ _ _)
(p (Seq.head c) (List.Tot.hd l));
let _ = seq_seq_match_tail_intro
p _ _ 1 _ _
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.tail c) (Seq.seq_of_list (List.Tot.tl l)) 0 (List.Tot.length (List.Tot.tl l)));
seq_seq_match_seq_list_match p _ (List.Tot.tl l);
rewrite
(seq_list_match_cons0 c l p seq_list_match)
(seq_list_match c l p)
let rec seq_list_match_seq_seq_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
True
(fun _ -> Seq.length c == List.Tot.length l)
(decreases l)
= match l with
| [] ->
rewrite
(seq_list_match c l p)
(seq_list_match_nil0 c);
let _ = gen_elim () in
on_range_empty
(seq_seq_match_item p c (Seq.seq_of_list l))
0
(List.Tot.length l)
| a :: q ->
let _l_nonempty : squash (Cons? l) = () in
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
noop ();
rewrite
(seq_list_match c l p)
(seq_list_match_cons0 c l p seq_list_match);
let _ = gen_elim () in
let a' = vpattern (fun a' -> p a' _) in
let c' = vpattern (fun c' -> seq_list_match c' _ _) in
Seq.lemma_cons_inj (Seq.head c) a' (Seq.tail c) c';
assert (a' == Seq.head c);
assert (c' == Seq.tail c);
noop ();
seq_list_match_seq_seq_match p _ _;
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.slice c 1 (Seq.length c)) (Seq.slice (Seq.seq_of_list l) 1 (Seq.length (Seq.seq_of_list l))) 0 (List.Tot.length (List.Tot.tl l)));
let _ = seq_seq_match_tail_elim
p c (Seq.seq_of_list l) 1 0 (List.Tot.length (List.Tot.tl l))
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p c (Seq.seq_of_list l) 1 (List.Tot.length l));
rewrite
(p _ _)
(seq_seq_match_item p c (Seq.seq_of_list l) 0);
on_range_cons
(seq_seq_match_item p _ _)
0 1 (List.Tot.length l)
let seq_seq_match_seq_list_match_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p `star` (seq_list_match c l p `implies_` seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l)))
(Seq.length c == List.Tot.length l)
(fun _ -> True)
= seq_seq_match_seq_list_match p c l;
intro_implies
(seq_list_match c l p)
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
emp
(fun _ -> seq_list_match_seq_seq_match p c l)
let seq_list_match_seq_seq_match_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) `star` (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) `implies_` seq_list_match c l p))
True
(fun _ -> Seq.length c == List.Tot.length l)
= seq_list_match_seq_seq_match p c l;
intro_implies
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(seq_list_match c l p)
emp
(fun _ -> seq_seq_match_seq_list_match p c l)
let seq_list_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_list_match c l p)
True
(fun _ -> Seq.length c == List.Tot.length l)
= seq_list_match_seq_seq_match_with_implies p c l;
seq_seq_match_length p _ _ _ _;
elim_implies
(seq_seq_match p _ _ _ _)
(seq_list_match c l p)
let seq_list_match_index
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: list t2)
(i: nat)
: STGhost (squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1)) opened
(seq_list_match s1 s2 p)
(fun _ ->
p (Seq.index s1 i) (List.Tot.index s2 i) `star`
(p (Seq.index s1 i) (List.Tot.index s2 i) `implies_`
seq_list_match s1 s2 p)
)
(i < Seq.length s1 \/ i < List.Tot.length s2)
(fun _ -> True)
= seq_list_match_seq_seq_match_with_implies p s1 s2;
let res : squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1) = () in
on_range_focus (seq_seq_match_item p s1 (Seq.seq_of_list s2)) 0 i (List.Tot.length s2);
rewrite_with_implies
(seq_seq_match_item p _ _ _)
(p (Seq.index s1 i) (List.Tot.index s2 i));
implies_trans
(p (Seq.index s1 i) (List.Tot.index s2 i))
(seq_seq_match_item p _ _ _)
(seq_seq_match p s1 (Seq.seq_of_list s2) 0 (List.Tot.length s2));
implies_trans
(p (Seq.index s1 i) (List.Tot.index s2 i))
(seq_seq_match p s1 (Seq.seq_of_list s2) 0 (List.Tot.length s2))
(seq_list_match s1 s2 p);
res
(* Random array access
Since `seq_list_match` is defined recursively on the list of
high-level values, it is used naturally left-to-right. By contrast,
in practice, an application may populate an array in a different
order, or even out-of-order. `seq_seq_match` supports that scenario
better, as we show below.
*)
let seq_map (#t1 #t2: Type) (f: t1 -> t2) (s: Seq.seq t1) : Tot (Seq.seq t2) =
Seq.init (Seq.length s) (fun i -> f (Seq.index s i))
let item_match_option
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(x1: t1)
(x2: option t2)
: Tot vprop
= match x2 with
| None -> emp
| Some x2' -> p x1 x2' | {
"checked_file": "/",
"dependencies": [
"Steel.ST.OnRange.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Steel.ST.SeqMatch.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.OnRange",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
p: (_: t1 -> _: t2 -> Steel.Effect.Common.vprop) ->
s1: FStar.Seq.Base.seq t1 ->
s2: FStar.Seq.Base.seq t2 ->
i: Prims.nat ->
j: Prims.nat
-> Steel.ST.Effect.Ghost.STGhostT Prims.unit | Steel.ST.Effect.Ghost.STGhostT | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"FStar.Seq.Base.seq",
"Prims.nat",
"Steel.ST.OnRange.on_range_weaken",
"Steel.ST.SeqMatch.seq_seq_match_item",
"FStar.Pervasives.Native.option",
"Steel.ST.SeqMatch.item_match_option",
"Steel.ST.SeqMatch.seq_map",
"FStar.Pervasives.Native.Some",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Steel.ST.Util.rewrite",
"Prims.unit",
"Steel.ST.SeqMatch.seq_seq_match"
] | [] | false | true | false | false | false | let seq_seq_match_item_match_option_elim
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit
opened
(seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
(fun _ -> seq_seq_match p s1 s2 i j) =
| on_range_weaken (seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
(seq_seq_match_item p s1 s2)
i
j
(fun k ->
rewrite (seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)
(seq_seq_match_item p s1 s2 k)) | false |
Trace.fst | Trace.tick_last | val tick_last : ns: Prims.list Prims.string -> Prims.list Prims.string | let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs) | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 62,
"start_col": 0,
"start_line": 58
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | ns: Prims.list Prims.string -> Prims.list Prims.string | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Prims.string",
"Prims.Nil",
"Prims.Cons",
"Prims.op_Hat",
"Trace.tick_last"
] | [
"recursion"
] | false | false | false | true | false | let rec tick_last (ns: list string) =
| match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x :: xs -> x :: (tick_last xs) | false |
|
FStar.UInt.fst | FStar.UInt.lemma_lognot_one_ext | val lemma_lognot_one_ext: #n:pos -> a:uint_t n ->
Lemma (lognot #(n+1) (one_extend a) = lognot #n a) | val lemma_lognot_one_ext: #n:pos -> a:uint_t n ->
Lemma (lognot #(n+1) (one_extend a) = lognot #n a) | let lemma_lognot_one_ext #n a =
let lhs = lognot #(n+1) (one_extend a) in
let rhs = lognot #n a in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot #n a) in
let eav = Seq.append hd1 av in
append_lemma #1 #n hd1 av;
append_lemma #1 #n hd0 nav;
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd0 nav in
Seq.Base.lemma_eq_elim neav_l neav_r | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 512,
"start_col": 0,
"start_line": 498
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a)
#push-options "--z3rlimit 40"
let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a)
#pop-options
#push-options "--fuel 1 --ifuel 0 --z3rlimit 40"
let lemma_lognot_zero_ext #n a =
let lhs = lognot #(n+1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n+1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n+1) eav = from_vec #n av);
assert (from_vec #(n+1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n+1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n+1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i:pos{i < n+1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.lognot (FStar.UInt.one_extend a) = FStar.UInt.lognot a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"FStar.Seq.Base.lemma_eq_elim",
"Prims.bool",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.append",
"FStar.BitVector.bv_t",
"Prims.op_Addition",
"FStar.BitVector.lognot_vec",
"Prims.unit",
"FStar.UInt.append_lemma",
"FStar.UInt.to_vec",
"FStar.UInt.lognot",
"FStar.Seq.Base.create",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"FStar.UInt.one_extend"
] | [] | true | false | true | false | false | let lemma_lognot_one_ext #n a =
| let lhs = lognot #(n + 1) (one_extend a) in
let rhs = lognot #n a in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot #n a) in
let eav = Seq.append hd1 av in
append_lemma #1 #n hd1 av;
append_lemma #1 #n hd0 nav;
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n + 1) eav in
let neav_l = Seq.append hd0 nav in
Seq.Base.lemma_eq_elim neav_l neav_r | false |
FStar.UInt.fst | FStar.UInt.lemma_lognot_value_nonzero | val lemma_lognot_value_nonzero: #n:pos -> a:uint_t n{a <> 0} ->
Lemma (lognot a = sub_mod (sub_mod 0 a) 1) | val lemma_lognot_value_nonzero: #n:pos -> a:uint_t n{a <> 0} ->
Lemma (lognot a = sub_mod (sub_mod 0 a) 1) | let lemma_lognot_value_nonzero #n a =
let p = pow2 n in
lemma_lognot_value_variation #n a;
assert (lognot a = (-a) % (pow2 n) - 1 % (pow2 n));
assert (sub_mod (sub_mod 0 a) 1 = (((0 - a) % p) - 1) % p);
lemma_mod_variation #n a;
assert (((-a) % p) - 1 % p = (((-a) % p) - 1) % p);
assert ((-a) % p - 1 % p = (((0 - a) % p) - 1) % p) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 609,
"start_col": 0,
"start_line": 602
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a)
#push-options "--z3rlimit 40"
let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a)
#pop-options
#push-options "--fuel 1 --ifuel 0 --z3rlimit 40"
let lemma_lognot_zero_ext #n a =
let lhs = lognot #(n+1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n+1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n+1) eav = from_vec #n av);
assert (from_vec #(n+1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n+1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n+1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i:pos{i < n+1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs)
let lemma_lognot_one_ext #n a =
let lhs = lognot #(n+1) (one_extend a) in
let rhs = lognot #n a in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot #n a) in
let eav = Seq.append hd1 av in
append_lemma #1 #n hd1 av;
append_lemma #1 #n hd0 nav;
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd0 nav in
Seq.Base.lemma_eq_elim neav_l neav_r
#push-options "--z3rlimit 60"
let rec lemma_lognot_value_mod #n a =
if n = 1 then () else
begin
assert (-pow2 n <= (-(a+1)) && -(a+1) < 0);
let av = to_vec a in
let hd = from_vec #1 (Seq.slice (to_vec a) 0 1) in
let tl = from_vec #(n-1) (Seq.slice (to_vec a) 1 n) in
assert (hd = 0 || hd = 1);
let hdpow = op_Multiply hd (pow2 (n-1)) in
from_vec_propriety (to_vec a) 1;
assert (from_vec av = (op_Multiply
(from_vec #1 (Seq.slice av 0 1)) (pow2 (n-1))) +
(from_vec #(n-1) (Seq.slice av 1 n)));
let ntl = lognot tl in
lemma_lognot_value_mod #(n-1) tl;
assert (ntl = pow2 (n-1) - tl - 1);
assert (a = hdpow + tl);
assert (lognot a = lognot #n (hdpow + tl));
assert (tl < pow2 (n-1));
if hdpow = 0 then
begin
assert (lognot a = lognot #n tl);
lemma_lognot_zero_ext #(n-1) tl;
lemma_zero_extend tl
end
else
begin
lemma_lognot_one_ext #(n-1) tl;
lemma_one_extend tl
end
end
#pop-options
let lemma_lognot_value_zero #n a =
let p = pow2 n in
calc (==) {
sub_mod (sub_mod 0 a) 1;
== { }
sub_mod ((0 - a) % p) 1;
== { }
((0 - a) % p - 1) % p;
== { }
(0 % p - 1) % p;
== { modulo_lemma 0 p }
(0 - 1) % p;
== { lemma_mod_sub_0 p }
p - 1;
== { }
p - 0 - 1;
== { lemma_lognot_value_mod a }
lognot a;
}
#pop-options
#push-options "--z3rlimit 150"
private
val lemma_mod_variation: #n:pos -> a:uint_t n ->
Lemma (a <> 0 ==> ((-a) % pow2 n) - 1 % pow2 n = (((-a) % pow2 n) - 1) % pow2 n)
let lemma_mod_variation #n a = ()
#pop-options
let lemma_one_mod_pow2 #n = ()
#push-options "--z3rlimit 50"
private
val lemma_lognot_value_variation: #n:pos -> a:uint_t n{a <> 0} ->
Lemma (lognot a = (-a) % pow2 n - 1 % pow2 n)
let lemma_lognot_value_variation #n a =
let p = pow2 n in
calc (==) {
lognot a <: int;
== { lemma_lognot_value_mod a }
p - a - 1;
== { FStar.Math.Lemmas.modulo_lemma a p }
p - (a % p) - 1;
== { FStar.Math.Lemmas.modulo_lemma 1 p }
(p - (a % p)) - (1 % p);
== { FStar.Math.Lemmas.lemma_mod_sub_1 a p }
(-a) % p - 1 % p;
}
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | a: FStar.UInt.uint_t n {a <> 0}
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.lognot a = FStar.UInt.sub_mod (FStar.UInt.sub_mod 0 a) 1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"Prims._assert",
"Prims.op_Equality",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"Prims.op_Minus",
"Prims.unit",
"FStar.UInt.lemma_mod_variation",
"FStar.UInt.sub_mod",
"FStar.UInt.lognot",
"Prims.pow2",
"FStar.UInt.lemma_lognot_value_variation"
] | [] | true | false | true | false | false | let lemma_lognot_value_nonzero #n a =
| let p = pow2 n in
lemma_lognot_value_variation #n a;
assert (lognot a = (- a) % (pow2 n) - 1 % (pow2 n));
assert (sub_mod (sub_mod 0 a) 1 = (((0 - a) % p) - 1) % p);
lemma_mod_variation #n a;
assert (((- a) % p) - 1 % p = (((- a) % p) - 1) % p);
assert ((- a) % p - 1 % p = (((0 - a) % p) - 1) % p) | false |
FStar.UInt.fst | FStar.UInt.lemma_lognot_zero_ext | val lemma_lognot_zero_ext: #n:pos -> a:uint_t n ->
Lemma (lognot #(n+1) (zero_extend a) = pow2 n + (lognot #n a)) | val lemma_lognot_zero_ext: #n:pos -> a:uint_t n ->
Lemma (lognot #(n+1) (zero_extend a) = pow2 n + (lognot #n a)) | let lemma_lognot_zero_ext #n a =
let lhs = lognot #(n+1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n+1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n+1) eav = from_vec #n av);
assert (from_vec #(n+1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n+1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n+1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i:pos{i < n+1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 496,
"start_col": 0,
"start_line": 467
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a)
#push-options "--z3rlimit 40"
let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a)
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.lognot (FStar.UInt.zero_extend a) = Prims.pow2 n + FStar.UInt.lognot a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.op_Addition",
"FStar.UInt.from_vec",
"Prims.unit",
"FStar.Seq.Base.seq",
"Prims.bool",
"FStar.Seq.Base.lemma_eq_intro",
"Prims.l_Forall",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Prims.int",
"Prims.pow2",
"Prims.op_Multiply",
"FStar.UInt.append_lemma",
"FStar.Seq.Base.append",
"FStar.BitVector.bv_t",
"FStar.BitVector.lognot_vec",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt.to_vec",
"FStar.UInt.lognot",
"FStar.Seq.Base.create",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length"
] | [] | false | false | true | false | false | let lemma_lognot_zero_ext #n a =
| let lhs = lognot #(n + 1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n + 1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n + 1) eav = from_vec #n av);
assert (from_vec #(n + 1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n + 1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n + 1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n + 1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i: pos{i < n + 1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs) | false |
FStar.UInt.fst | FStar.UInt.lemma_one_extend | val lemma_one_extend: #n:pos -> a:uint_t n ->
Lemma (one_extend a = pow2 n + a)
[SMTPat (one_extend a)] | val lemma_one_extend: #n:pos -> a:uint_t n ->
Lemma (one_extend a = pow2 n + a)
[SMTPat (one_extend a)] | let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 463,
"start_col": 0,
"start_line": 455
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.one_extend a = Prims.pow2 n + a)
[SMTPat (FStar.UInt.one_extend a)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.pow2",
"Prims.unit",
"FStar.UInt.from_vec_propriety",
"FStar.UInt.from_vec",
"FStar.UInt.append_lemma",
"FStar.UInt.one_extend",
"FStar.Seq.Base.seq",
"Prims.bool",
"FStar.Seq.Base.append",
"FStar.BitVector.bv_t",
"FStar.UInt.to_vec",
"FStar.Seq.Base.create"
] | [] | true | false | true | false | false | let lemma_one_extend #n a =
| let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n + 1) eav 1;
assert (r = pow2 n + a) | false |
Trace.fst | Trace.fact | val fact (n: nat) : Tot nat | val fact (n: nat) : Tot nat | let fact (n : nat) : Tot nat = fact_aux n 1 | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 179,
"start_col": 0,
"start_line": 179
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z)
let cons_fst_qn = ["Trace"; "cons_fst"]
let term_is_fv hd nm : Tac bool =
match inspect hd with
| Tv_FVar fv -> inspect_fv fv = inspect_fv nm
| _ -> false
noeq
type ins_info = {
orig_name : fv;
ins_name : fv;
args : (args : list term{length args <= 8});
trace_arg : term;
}
let rec instrument_body (ii : ins_info) (t : term) : Tac term =
match inspect_unascribe t with
// descend into matches
| Tv_Match t ret_opt brs -> begin
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
end
// descend into lets
| Tv_Let r attrs b t1 t2 -> begin
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
end
| _ -> begin
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then begin
// modify the tail call
// turn `nm <b1,...,bn>` into `nm' (<a1,...,an>::tr) <b1,...,bn>`
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
end else begin
// not a tail call, record the current set of args and be done
mkpair (mk_cons argpack ii.trace_arg) t
end
end
and ins_br (ii : ins_info) (br : branch) : Tac branch =
let (p, t) = br in
let t' = instrument_body ii t in
(p, t')
let rec cutlast (l : list 'a{length l > 0}) : list 'a * 'a =
match l with
| [x] -> [], x
| x::xs -> let ys, y = cutlast xs in x::ys, y
let instrument (f : 'a) : Tac unit =
let t = quote f in
// name
let n = match inspect t with
| Tv_FVar fv -> fv
| _ -> fail "Not a top-level"
in
let n' = tick n in
let all_args = intros () in
if length all_args = 0 then
fail "Function has no arguments?";
let real, trace_arg = cutlast all_args in
let real = map (fun b -> pack (Tv_Var (binding_to_namedv b))) real in
if length real > 8 then
fail "Too many arguments to instrument function";
assert (length real <= 8);
let ii = {
orig_name = n;
ins_name = n';
args = real;
trace_arg = pack (Tv_Var (binding_to_namedv trace_arg))
} in
(* Apply the function to the arguments and unfold it. This will only
* unfold it once, so recursive calls are present *)
let t = norm_term [delta; zeta] (mk_e_app t ii.args) in
dup ();
let t = instrument_body ii t in
(* dump ""; *)
let _ = focus (fun () -> exact_guard t; repeat smt) in
norm [];
trefl ()
let rec fall (n : mynat) : Tot mynat =
match n with
| Z -> Z
| S n -> fall n
// Because of the way we're building this recursive function, its termination is unprovable.
// So admit queries for now.
#push-options "--admit_smt_queries true"
let rec fall' (n : mynat) (l : list mynat) =
// We need to annotate the result type.. which sucks.
// But we could use a tactic later :)
synth_by_tactic #(mynat -> list mynat -> (list mynat * mynat)) (fun () -> instrument fall) n l
#pop-options
let _ = assert (fall' (S (S (S Z))) [] == ([Z; S Z; S (S Z); S (S (S Z))], Z))
// Beware: the `let acc' = `... gets normalized in the tactic,
// so we're not actually descending through it. Maybe we need a flag
// to control the evaluation of lets.
let rec fact_aux (n acc : nat) : Tot nat =
if n = 0
then acc
else let acc' = acc `op_Multiply` n in fact_aux (n - 1) acc' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | n: Prims.nat -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Trace.fact_aux"
] | [] | false | false | false | true | false | let fact (n: nat) : Tot nat =
| fact_aux n 1 | false |
Trace.fst | Trace.instrument_body | val instrument_body (ii: ins_info) (t: term) : Tac term | val instrument_body (ii: ins_info) (t: term) : Tac term | let rec instrument_body (ii : ins_info) (t : term) : Tac term =
match inspect_unascribe t with
// descend into matches
| Tv_Match t ret_opt brs -> begin
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
end
// descend into lets
| Tv_Let r attrs b t1 t2 -> begin
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
end
| _ -> begin
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then begin
// modify the tail call
// turn `nm <b1,...,bn>` into `nm' (<a1,...,an>::tr) <b1,...,bn>`
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
end else begin
// not a tail call, record the current set of args and be done
mkpair (mk_cons argpack ii.trace_arg) t
end
end
and ins_br (ii : ins_info) (br : branch) : Tac branch =
let (p, t) = br in
let t' = instrument_body ii t in
(p, t') | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 116,
"start_col": 0,
"start_line": 86
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z)
let cons_fst_qn = ["Trace"; "cons_fst"]
let term_is_fv hd nm : Tac bool =
match inspect hd with
| Tv_FVar fv -> inspect_fv fv = inspect_fv nm
| _ -> false
noeq
type ins_info = {
orig_name : fv;
ins_name : fv;
args : (args : list term{length args <= 8});
trace_arg : term;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | ii: Trace.ins_info -> t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | FStar.Tactics.Effect.Tac | [] | [
"instrument_body",
"ins_br"
] | [
"Trace.ins_info",
"FStar.Tactics.NamedView.term",
"FStar.Pervasives.Native.option",
"FStar.Tactics.NamedView.match_returns_ascription",
"Prims.list",
"FStar.Tactics.NamedView.branch",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_Match",
"FStar.Tactics.Util.map",
"Trace.ins_br",
"Prims.bool",
"FStar.Tactics.NamedView.simple_binder",
"FStar.Tactics.NamedView.Tv_Let",
"Trace.instrument_body",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Stubs.Reflection.V2.Data.argv",
"FStar.Reflection.V2.Derived.mk_app",
"FStar.List.Tot.Base.op_At",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Reflection.V2.Derived.mk_cons",
"Trace.__proj__Mkins_info__item__trace_arg",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"Prims.Nil",
"FStar.Tactics.NamedView.Tv_FVar",
"Trace.__proj__Mkins_info__item__ins_name",
"FStar.Reflection.V2.Derived.mkpair",
"Trace.term_is_fv",
"Trace.__proj__Mkins_info__item__orig_name",
"FStar.Reflection.V2.Derived.mktuple_n",
"Trace.__proj__Mkins_info__item__args",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.SyntaxHelpers.collect_app",
"FStar.Tactics.NamedView.term_view",
"Prims.b2t",
"FStar.Tactics.NamedView.notAscription",
"FStar.Tactics.V2.SyntaxHelpers.inspect_unascribe"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec instrument_body (ii: ins_info) (t: term) : Tac term =
| match inspect_unascribe t with
| Tv_Match t ret_opt brs ->
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
| Tv_Let r attrs b t1 t2 ->
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
| _ ->
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
else mkpair (mk_cons argpack ii.trace_arg) t | false |
Steel.ST.SeqMatch.fst | Steel.ST.SeqMatch.seq_seq_match_item_match_option_intro | val seq_seq_match_item_match_option_intro
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit
opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j) | val seq_seq_match_item_match_option_intro
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit
opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j) | let seq_seq_match_item_match_option_intro
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
= on_range_weaken
(seq_seq_match_item p s1 s2)
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
i j
(fun k ->
rewrite
(seq_seq_match_item p s1 s2 k)
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)
) | {
"file_name": "lib/steel/Steel.ST.SeqMatch.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 649,
"start_col": 0,
"start_line": 631
} | module Steel.ST.SeqMatch
include Steel.ST.OnRange
open Steel.ST.GenElim
module Seq = FStar.Seq
module SZ = FStar.SizeT
(* `seq_list_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a list of high-level
values. `seq_list_match` is carefully designed to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values. *)
[@@__reduce__]
let seq_list_match_nil0
(#t: Type)
(c: Seq.seq t)
: Tot vprop
= pure (c `Seq.equal` Seq.empty)
[@@__reduce__]
let seq_list_match_cons0
(#t #t': Type)
(c: Seq.seq t)
(l: list t' { Cons? l })
(item_match: (t -> (v': t' { v' << l }) -> vprop))
(seq_list_match: (Seq.seq t -> (v': list t') -> (raw_data_item_match: (t -> (v'': t' { v'' << v' }) -> vprop) { v' << l }) ->
vprop))
: Tot vprop
= exists_ (fun (c1: t) -> exists_ (fun (c2: Seq.seq t) ->
item_match c1 (List.Tot.hd l) `star`
seq_list_match c2 (List.Tot.tl l) item_match `star`
pure (c `Seq.equal` Seq.cons c1 c2)
))
let rec seq_list_match
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Tot vprop
(decreases v)
= if Nil? v
then seq_list_match_nil0 c
else seq_list_match_cons0 c v item_match seq_list_match
let seq_list_match_cons_eq
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Lemma
(requires (Cons? v))
(ensures (
seq_list_match c v item_match ==
seq_list_match_cons0 c v item_match seq_list_match
))
= let a :: q = v in
assert_norm (seq_list_match c (a :: q) item_match ==
seq_list_match_cons0 c (a :: q) item_match seq_list_match
)
let seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhost unit opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\
Nil? v)
(fun _ -> True)
= noop ();
rewrite
(seq_list_match_nil0 c)
(seq_list_match c v item_match)
let list_cons_precedes
(#t: Type)
(a: t)
(q: list t)
: Lemma
((a << a :: q) /\ (q << a :: q))
[SMTPat (a :: q)]
= assert (List.Tot.hd (a :: q) << (a :: q));
assert (List.Tot.tl (a :: q) << (a :: q))
let seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a' : t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << a' :: v }) -> vprop))
: STGhostT unit opened
(item_match a a' `star` seq_list_match c v item_match)
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match)
= seq_list_match_cons_eq (Seq.cons a c) (a' :: v) item_match;
noop ();
rewrite
(seq_list_match_cons0 (Seq.cons a c) (a' :: v) item_match seq_list_match)
(seq_list_match (Seq.cons a c) (a' :: v) item_match)
let seq_list_match_cons_elim
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t' { Cons? v \/ Seq.length c > 0 })
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhostT (squash (Cons? v /\ Seq.length c > 0)) opened
(seq_list_match c v item_match)
(fun _ -> item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
= if Nil? v
then begin
rewrite
(seq_list_match c v item_match)
(seq_list_match_nil0 c);
let _ = gen_elim () in
assert False;
rewrite // by contradiction
emp
(item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
end else begin
seq_list_match_cons_eq c v item_match;
noop ();
rewrite
(seq_list_match c v item_match)
(seq_list_match_cons0 c v item_match seq_list_match);
let _ = gen_elim () in
let prf : squash (Cons? v /\ Seq.length c > 0) = () in
let c1 = vpattern (fun c1 -> item_match c1 (List.Tot.hd v)) in
let c2 = vpattern (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) in
Seq.lemma_cons_inj c1 (Seq.head c) c2 (Seq.tail c);
vpattern_rewrite (fun c1 -> item_match c1 (List.Tot.hd v)) (Seq.head c);
vpattern_rewrite (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) (Seq.tail c);
prf
end
// this one cannot be proven with seq_seq_match because of the << refinement in the type of item_match
let rec seq_list_match_weaken
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match1 item_match2: (t -> (v': t' { v' << v }) -> vprop))
(prf: (
(#opened: _) ->
(c': t) ->
(v': t' { v' << v }) ->
STGhostT unit opened
(item_match1 c' v')
(fun _ -> item_match2 c' v')
))
: STGhostT unit opened
(seq_list_match c v item_match1)
(fun _ -> seq_list_match c v item_match2)
(decreases v)
= if Nil? v
then
rewrite (seq_list_match c v item_match1) (seq_list_match c v item_match2)
else begin
let _ : squash (Cons? v) = () in
seq_list_match_cons_eq c v item_match1;
seq_list_match_cons_eq c v item_match2;
rewrite
(seq_list_match c v item_match1)
(seq_list_match_cons0 c v item_match1 seq_list_match);
let _ = gen_elim () in
prf _ _;
seq_list_match_weaken _ (List.Tot.tl v) item_match1 item_match2 prf;
rewrite
(seq_list_match_cons0 c v item_match2 seq_list_match)
(seq_list_match c v item_match2)
end
(* `seq_seq_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a sequence of high-level
values. Contrary to `seq_list_match`, `seq_seq_match` is not meant to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values, because no lemma ensures that `Seq.index s i << s` *)
let seq_seq_match_item
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i: nat)
: Tot vprop
= if i < Seq.length c && i < Seq.length l
then
p (Seq.index c i) (Seq.index l i)
else
pure (squash False)
let seq_seq_match_item_tail
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat)
(i: nat)
: Lemma
(requires (
i + delta <= Seq.length c /\
i + delta <= Seq.length l
))
(ensures (
seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i ==
seq_seq_match_item p c l (i + delta)
))
= ()
[@@__reduce__]
let seq_seq_match
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i j: nat)
: Tot vprop
= on_range (seq_seq_match_item p c l) i j
let seq_seq_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match p s1 s2 i j)
True
(fun _ -> i <= j /\ (i == j \/ (j <= Seq.length s1 /\ j <= Seq.length s2)))
= on_range_le (seq_seq_match_item p s1 s2) i j;
if i = j
then noop ()
else begin
let j' = j - 1 in
if j' < Seq.length s1 && j' < Seq.length s2
then noop ()
else begin
on_range_unsnoc
(seq_seq_match_item p s1 s2)
i j' j;
rewrite
(seq_seq_match_item p _ _ _)
(pure (squash False));
let _ = gen_elim () in
rewrite
(seq_seq_match p s1 s2 i j')
(seq_seq_match p s1 s2 i j) // by contradiction
end
end
let seq_seq_match_weaken
(#opened: _)
(#t1 #t2: Type)
(p p': t1 -> t2 -> vprop)
(w: ((x1: t1) -> (x2: t2) -> STGhostT unit opened
(p x1 x2) (fun _ -> p' x1 x2)
))
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p' c1' c2' i j)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
=
on_range_weaken
(seq_seq_match_item p c1 c2)
(seq_seq_match_item p' c1' c2')
i j
(fun k ->
rewrite (seq_seq_match_item p c1 c2 k) (p (Seq.index (Seq.slice c1 i j) (k - i)) (Seq.index (Seq.slice c2 i j) (k - i)));
w _ _;
rewrite (p' _ _) (seq_seq_match_item p' c1' c2' k)
)
let seq_seq_match_weaken_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p c1' c2' i j `star`
(seq_seq_match p c1' c2' i j `implies_` seq_seq_match p c1 c2 i j)
)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
= seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1 c1'
c2 c2'
i j;
intro_implies
(seq_seq_match p c1' c2' i j)
(seq_seq_match p c1 c2 i j)
emp
(fun _ ->
seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1' c1
c2' c2
i j
)
(* Going between `seq_list_match` and `seq_seq_match` *)
let seq_seq_match_tail_elim
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq (t2))
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i j: nat)
: STGhostT unit opened
(seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i j)
(fun _ -> seq_seq_match p c l (i + delta) (j + delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(seq_seq_match_item p c l)
delta
i j
(fun k ->
if k < Seq.length c - delta && k < Seq.length l - delta
then begin
seq_seq_match_item_tail p c l delta k;
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(seq_seq_match_item p c l (k + delta))
end else begin
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p c l (k + delta)) // by contradiction
end
)
(i + delta) (j + delta)
let seq_seq_match_tail_intro
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i: nat {
delta <= i
})
(j: nat)
: STGhostT (squash (i <= j)) opened
(seq_seq_match p c l i j)
(fun _ -> seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (i - delta) (j - delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p c l)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(0 - delta)
i j
(fun k ->
if k < Seq.length c && k < Seq.length l
then begin
seq_seq_match_item_tail p c l delta (k - delta);
rewrite
(seq_seq_match_item p c l k)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta)))
end else begin
rewrite
(seq_seq_match_item p c l k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta))) // by contradiction
end
)
(i - delta) (j - delta)
let rec seq_seq_match_seq_list_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p)
(Seq.length c == List.Tot.length l)
(fun _ -> True)
(decreases l)
= match l with
| [] ->
drop (seq_seq_match p _ _ _ _);
rewrite
(seq_list_match_nil0 c)
(seq_list_match c l p)
| a :: q ->
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
on_range_uncons
(seq_seq_match_item p _ _)
_ 1 _;
rewrite
(seq_seq_match_item p _ _ _)
(p (Seq.head c) (List.Tot.hd l));
let _ = seq_seq_match_tail_intro
p _ _ 1 _ _
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.tail c) (Seq.seq_of_list (List.Tot.tl l)) 0 (List.Tot.length (List.Tot.tl l)));
seq_seq_match_seq_list_match p _ (List.Tot.tl l);
rewrite
(seq_list_match_cons0 c l p seq_list_match)
(seq_list_match c l p)
let rec seq_list_match_seq_seq_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
True
(fun _ -> Seq.length c == List.Tot.length l)
(decreases l)
= match l with
| [] ->
rewrite
(seq_list_match c l p)
(seq_list_match_nil0 c);
let _ = gen_elim () in
on_range_empty
(seq_seq_match_item p c (Seq.seq_of_list l))
0
(List.Tot.length l)
| a :: q ->
let _l_nonempty : squash (Cons? l) = () in
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
noop ();
rewrite
(seq_list_match c l p)
(seq_list_match_cons0 c l p seq_list_match);
let _ = gen_elim () in
let a' = vpattern (fun a' -> p a' _) in
let c' = vpattern (fun c' -> seq_list_match c' _ _) in
Seq.lemma_cons_inj (Seq.head c) a' (Seq.tail c) c';
assert (a' == Seq.head c);
assert (c' == Seq.tail c);
noop ();
seq_list_match_seq_seq_match p _ _;
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.slice c 1 (Seq.length c)) (Seq.slice (Seq.seq_of_list l) 1 (Seq.length (Seq.seq_of_list l))) 0 (List.Tot.length (List.Tot.tl l)));
let _ = seq_seq_match_tail_elim
p c (Seq.seq_of_list l) 1 0 (List.Tot.length (List.Tot.tl l))
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p c (Seq.seq_of_list l) 1 (List.Tot.length l));
rewrite
(p _ _)
(seq_seq_match_item p c (Seq.seq_of_list l) 0);
on_range_cons
(seq_seq_match_item p _ _)
0 1 (List.Tot.length l)
let seq_seq_match_seq_list_match_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p `star` (seq_list_match c l p `implies_` seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l)))
(Seq.length c == List.Tot.length l)
(fun _ -> True)
= seq_seq_match_seq_list_match p c l;
intro_implies
(seq_list_match c l p)
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
emp
(fun _ -> seq_list_match_seq_seq_match p c l)
let seq_list_match_seq_seq_match_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) `star` (seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l) `implies_` seq_list_match c l p))
True
(fun _ -> Seq.length c == List.Tot.length l)
= seq_list_match_seq_seq_match p c l;
intro_implies
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(seq_list_match c l p)
emp
(fun _ -> seq_seq_match_seq_list_match p c l)
let seq_list_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_list_match c l p)
(fun _ -> seq_list_match c l p)
True
(fun _ -> Seq.length c == List.Tot.length l)
= seq_list_match_seq_seq_match_with_implies p c l;
seq_seq_match_length p _ _ _ _;
elim_implies
(seq_seq_match p _ _ _ _)
(seq_list_match c l p)
let seq_list_match_index
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: list t2)
(i: nat)
: STGhost (squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1)) opened
(seq_list_match s1 s2 p)
(fun _ ->
p (Seq.index s1 i) (List.Tot.index s2 i) `star`
(p (Seq.index s1 i) (List.Tot.index s2 i) `implies_`
seq_list_match s1 s2 p)
)
(i < Seq.length s1 \/ i < List.Tot.length s2)
(fun _ -> True)
= seq_list_match_seq_seq_match_with_implies p s1 s2;
let res : squash (i < Seq.length s1 /\ List.Tot.length s2 == Seq.length s1) = () in
on_range_focus (seq_seq_match_item p s1 (Seq.seq_of_list s2)) 0 i (List.Tot.length s2);
rewrite_with_implies
(seq_seq_match_item p _ _ _)
(p (Seq.index s1 i) (List.Tot.index s2 i));
implies_trans
(p (Seq.index s1 i) (List.Tot.index s2 i))
(seq_seq_match_item p _ _ _)
(seq_seq_match p s1 (Seq.seq_of_list s2) 0 (List.Tot.length s2));
implies_trans
(p (Seq.index s1 i) (List.Tot.index s2 i))
(seq_seq_match p s1 (Seq.seq_of_list s2) 0 (List.Tot.length s2))
(seq_list_match s1 s2 p);
res
(* Random array access
Since `seq_list_match` is defined recursively on the list of
high-level values, it is used naturally left-to-right. By contrast,
in practice, an application may populate an array in a different
order, or even out-of-order. `seq_seq_match` supports that scenario
better, as we show below.
*)
let seq_map (#t1 #t2: Type) (f: t1 -> t2) (s: Seq.seq t1) : Tot (Seq.seq t2) =
Seq.init (Seq.length s) (fun i -> f (Seq.index s i))
let item_match_option
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(x1: t1)
(x2: option t2)
: Tot vprop
= match x2 with
| None -> emp
| Some x2' -> p x1 x2'
let seq_seq_match_item_match_option_elim
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit opened
(seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j)
(fun _ -> seq_seq_match p s1 s2 i j)
= on_range_weaken
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
(seq_seq_match_item p s1 s2)
i j
(fun k ->
rewrite
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)
(seq_seq_match_item p s1 s2 k)
) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.OnRange.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Steel.ST.SeqMatch.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.OnRange",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
p: (_: t1 -> _: t2 -> Steel.Effect.Common.vprop) ->
s1: FStar.Seq.Base.seq t1 ->
s2: FStar.Seq.Base.seq t2 ->
i: Prims.nat ->
j: Prims.nat
-> Steel.ST.Effect.Ghost.STGhostT Prims.unit | Steel.ST.Effect.Ghost.STGhostT | [] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"FStar.Seq.Base.seq",
"Prims.nat",
"Steel.ST.OnRange.on_range_weaken",
"Steel.ST.SeqMatch.seq_seq_match_item",
"FStar.Pervasives.Native.option",
"Steel.ST.SeqMatch.item_match_option",
"Steel.ST.SeqMatch.seq_map",
"FStar.Pervasives.Native.Some",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Steel.ST.Util.rewrite",
"Prims.unit",
"Steel.ST.SeqMatch.seq_seq_match"
] | [] | false | true | false | false | false | let seq_seq_match_item_match_option_intro
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhostT unit
opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match (item_match_option p) s1 (seq_map Some s2) i j) =
| on_range_weaken (seq_seq_match_item p s1 s2)
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2))
i
j
(fun k ->
rewrite (seq_seq_match_item p s1 s2 k)
(seq_seq_match_item (item_match_option p) s1 (seq_map Some s2) k)) | false |
Trace.fst | Trace.ins_br | val ins_br (ii: ins_info) (br: branch) : Tac branch | val ins_br (ii: ins_info) (br: branch) : Tac branch | let rec instrument_body (ii : ins_info) (t : term) : Tac term =
match inspect_unascribe t with
// descend into matches
| Tv_Match t ret_opt brs -> begin
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
end
// descend into lets
| Tv_Let r attrs b t1 t2 -> begin
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
end
| _ -> begin
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then begin
// modify the tail call
// turn `nm <b1,...,bn>` into `nm' (<a1,...,an>::tr) <b1,...,bn>`
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
end else begin
// not a tail call, record the current set of args and be done
mkpair (mk_cons argpack ii.trace_arg) t
end
end
and ins_br (ii : ins_info) (br : branch) : Tac branch =
let (p, t) = br in
let t' = instrument_body ii t in
(p, t') | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 116,
"start_col": 0,
"start_line": 86
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z)
let cons_fst_qn = ["Trace"; "cons_fst"]
let term_is_fv hd nm : Tac bool =
match inspect hd with
| Tv_FVar fv -> inspect_fv fv = inspect_fv nm
| _ -> false
noeq
type ins_info = {
orig_name : fv;
ins_name : fv;
args : (args : list term{length args <= 8});
trace_arg : term;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | ii: Trace.ins_info -> br: FStar.Tactics.NamedView.branch
-> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.branch | FStar.Tactics.Effect.Tac | [] | [
"instrument_body",
"ins_br"
] | [
"Trace.ins_info",
"FStar.Tactics.NamedView.branch",
"FStar.Tactics.NamedView.pattern",
"FStar.Tactics.NamedView.term",
"FStar.Pervasives.Native.Mktuple2",
"Trace.instrument_body"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec ins_br (ii: ins_info) (br: branch) : Tac branch =
| let p, t = br in
let t' = instrument_body ii t in
(p, t') | false |
Lib.ByteSequence.fst | Lib.ByteSequence.some_arithmetic | val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma
(let m = numbytes t in
n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 ==
n / pow2 (8 * i) % pow2 8) | val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma
(let m = numbytes t in
n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 ==
n / pow2 (8 * i) % pow2 8) | let some_arithmetic t n i =
let m = numbytes t in
calc (==) {
n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8;
== { assert (bits t == 8 * m) }
n / pow2 ((8 * m) * (i / m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8;
== { FStar.Math.Lemmas.paren_mul_right 8 m (i / m);
FStar.Math.Lemmas.euclidean_division_definition i m }
n / pow2 (8 * (i - i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8;
== { Math.Lemmas.distributivity_sub_right 8 i (i % m) }
n / pow2 (8 * i - 8 * (i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8;
== { modulo_pow2_prop 8 (n / pow2 (8 * i - 8 * (i % m))) m (i % m) }
(n / pow2 (8 * i - 8 * (i % m))) / pow2 (8 * (i % m)) % pow2 8;
== { Math.Lemmas.division_multiplication_lemma n
(pow2 (8 * i - 8 * (i % m))) (pow2 (8 * (i % m))) }
(n / (pow2 (8 * i - 8 * (i % m)) * pow2 (8 * (i % m)))) % pow2 8;
== { Math.Lemmas.pow2_plus (8 * i - 8 * (i % m)) (8 * (i % m)) }
(n / pow2 (8 * i)) % pow2 8;
} | {
"file_name": "lib/Lib.ByteSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 625,
"start_col": 0,
"start_line": 607
} | module Lib.ByteSequence
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// BEGIN constant-time sequence equality
val lemma_not_equal_slice: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat -> j:nat ->
k:nat{i <= j /\ i <= k /\ j <= k /\ k <= Seq.length b1 /\ k <= Seq.length b2 } ->
Lemma
(requires ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j)))
(ensures ~(Seq.equal (Seq.slice b1 i k) (Seq.slice b2 i k)))
let lemma_not_equal_slice #a b1 b2 i j k =
assert (forall (n:nat{n < k - i}). Seq.index (Seq.slice b1 i k) n == Seq.index b1 (n + i))
val lemma_not_equal_last: #a:Type -> b1:Seq.seq a -> b2:Seq.seq a -> i:nat ->
j:nat{i < j /\ j <= Seq.length b1 /\ j <= Seq.length b2} ->
Lemma
(requires ~(Seq.index b1 (j - 1) == Seq.index b2 (j - 1)))
(ensures ~(Seq.equal (Seq.slice b1 i j) (Seq.slice b2 i j)))
let lemma_not_equal_last #a b1 b2 i j =
Seq.lemma_index_slice b1 i j (j - i - 1);
Seq.lemma_index_slice b2 i j (j - i - 1)
val seq_eq_mask_inner: #t:inttype{~(S128? t)} -> #len1:size_nat -> #len2:size_nat
-> b1:lseq (int_t t SEC) len1
-> b2:lseq (int_t t SEC) len2
-> len:size_nat{len <= len1 /\ len <= len2}
-> i:size_nat{i < len}
-> res:int_t t SEC{
(sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\
(sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC))}
-> res':int_t t SEC{
(sub b1 0 (i + 1) == sub b2 0 (i + 1) ==> v res' == v (ones t SEC)) /\
(sub b1 0 (i + 1) =!= sub b2 0 (i + 1) ==> v res' == v (zeros t SEC))}
let seq_eq_mask_inner #t #len1 #len2 b1 b2 len i res =
logand_zeros (ones t SEC);
logand_ones (ones t SEC);
logand_zeros (zeros t SEC);
logand_ones (zeros t SEC);
let z0 = res in
let res = eq_mask b1.[i] b2.[i] &. z0 in
logand_spec (eq_mask b1.[i] b2.[i]) z0;
if v res = ones_v t then
begin
let s1 = sub b1 0 (i + 1) in
let s2 = sub b2 0 (i + 1) in
Seq.lemma_split s1 i;
Seq.lemma_split s2 i;
assert (equal s1 s2)
end
else if v z0 = 0 then
lemma_not_equal_slice b1 b2 0 i (i + 1)
else
lemma_not_equal_last b1 b2 0 (i + 1);
res
let seq_eq_mask #t #len1 #len2 b1 b2 len =
repeati_inductive len
(fun (i:nat{i <= len}) res ->
(sub b1 0 i == sub b2 0 i ==> v res == v (ones t SEC)) /\
(sub b1 0 i =!= sub b2 0 i ==> v res == v (zeros t SEC)))
(seq_eq_mask_inner b1 b2 len)
(ones t SEC)
let lbytes_eq #len b1 b2 =
let res = seq_eq_mask b1 b2 len in
RawIntTypes.u8_to_UInt8 res = 255uy
/// END constant-time sequence equality
let mask_select #t mask a b =
b ^. (mask &. (a ^. b))
let mask_select_lemma #t mask a b =
let t1 = mask &. (a ^. b) in
let t2 = b ^. t1 in
logand_lemma mask (a ^.b);
if v mask = 0 then begin
assert (v t1 == 0);
logxor_lemma b t1;
assert (v t2 = v b);
() end
else begin
assert (v t1 == v (a ^. b));
logxor_lemma b a;
assert (v t2 = v a);
() end
let seq_mask_select #t #len a b mask =
let res = map2 (mask_select mask) a b in
let lemma_aux (i:nat{i < len}) : Lemma (v res.[i] == (if v mask = 0 then v b.[i] else v a.[i])) =
mask_select_lemma mask a.[i] b.[i] in
Classical.forall_intro lemma_aux;
if v mask = 0 then eq_intro res b else eq_intro res a;
res
val nat_from_intseq_be_:
#t:inttype{unsigned t} -> #l:secrecy_level
-> b:seq (uint_t t l)
-> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b))
let rec nat_from_intseq_be_ #t #l b =
let len = length b in
if len = 0 then 0
else
let l = v (Seq.index b (len - 1)) in
let pre = Seq.slice b 0 (len - 1) in
let shift = pow2 (bits t) in
let n' = nat_from_intseq_be_ pre in
Math.Lemmas.pow2_plus (bits t) (len * bits t - bits t);
l + shift * n'
let nat_from_intseq_be = nat_from_intseq_be_
val nat_from_intseq_le_:
#t:inttype{unsigned t} -> #l:secrecy_level
-> b:seq (uint_t t l)
-> Tot (n:nat{n < pow2 (length b * bits t)}) (decreases (length b))
let rec nat_from_intseq_le_ #t #l b =
let len = length b in
if len = 0 then 0
else
let shift = pow2 (bits t) in
let tt = Seq.slice b 1 len in
let n' = nat_from_intseq_le_ #t #l tt in
let l = v (Seq.index b 0) in
Math.Lemmas.pow2_plus (bits t) ( len * bits t - bits t);
let n = l + shift * n' in
n
let nat_from_intseq_le = nat_from_intseq_le_
#set-options "--max_fuel 1"
val nat_to_intseq_be_:
#t:inttype{unsigned t} -> #l:secrecy_level
-> len:nat
-> n:nat{n < pow2 (bits t * len)}
-> Tot (b:seq (int_t t l){length b == len /\ n == nat_from_intseq_be b}) (decreases len)
let rec nat_to_intseq_be_ #t #l len n =
if len = 0 then Seq.empty
else
let len' = len - 1 in
let tt = uint #t #l (n % modulus t) in
let n' = n / modulus t in
assert (modulus t = pow2 (bits t));
FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t);
let b' = nat_to_intseq_be_ len' n' in
let b = Seq.append b' (create 1 tt) in
Seq.append_slices b' (create 1 tt);
b
let nat_to_intseq_be = nat_to_intseq_be_
val nat_to_intseq_le_:
#t:inttype{unsigned t} -> #l:secrecy_level
-> len:nat
-> n:nat{n < pow2 (bits t * len)}
-> Tot (b:seq (uint_t t l){length b == len /\ n == nat_from_intseq_le b}) (decreases len)
let rec nat_to_intseq_le_ #t #l len n =
if len = 0 then Seq.empty
else
let len' = len - 1 in
let tt = uint #t #l (n % modulus t) in
let n' = n / modulus t in
assert (modulus t = pow2 (bits t));
FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t);
let b' = nat_to_intseq_le_ len' n' in
let b = Seq.append (create 1 tt) b' in
Seq.append_slices (create 1 tt) b';
b
let nat_to_intseq_le = nat_to_intseq_le_
/// These lemmas allow to unfold the definition of nat_to_intseq_{b}e without using
/// fuel > 0 below, which makes the proof more expensive
val head_nat_to_intseq_le:
#t:inttype{unsigned t}
-> #l:secrecy_level
-> len:size_pos
-> n:nat{n < pow2 (bits t * len)}
-> Lemma (Seq.index (nat_to_intseq_le #t #l len n) 0 ==
uint #t #l (n % pow2 (bits t)))
let head_nat_to_intseq_le #t #l len n = ()
val nat_to_intseq_le_pos:
#t:inttype{unsigned t}
-> #l:secrecy_level
-> len:size_pos
-> n:nat{n < pow2 (bits t * len)}
-> Lemma (nat_to_intseq_le #t #l len n ==
Seq.append (create 1 (uint #t #l (n % modulus t)))
(nat_to_intseq_le (len - 1) (n / modulus t)))
let nat_to_intseq_le_pos #t #l len n = ()
val head_nat_to_intseq_be:
#t:inttype{unsigned t}
-> #l:secrecy_level
-> len:size_pos
-> n:nat{n < pow2 (bits t * len)}
-> Lemma (Seq.index (nat_to_intseq_be #t #l len n) (len - 1) ==
uint #t #l (n % pow2 (bits t)))
let head_nat_to_intseq_be #t #l len n = ()
val nat_to_intseq_be_pos:
#t:inttype{unsigned t}
-> #l:secrecy_level
-> len:size_pos
-> n:nat{n < pow2 (bits t * len)}
-> Lemma (nat_to_intseq_be #t #l len n ==
Seq.append (nat_to_intseq_be (len - 1) (n / modulus t))
(create 1 (uint #t #l (n % modulus t))))
let nat_to_intseq_be_pos #t #l len n = ()
#push-options "--fuel 0 --ifuel 0"
let rec index_nat_to_intseq_le #t #l len n i =
if i = 0 then
if len = 0 then () else head_nat_to_intseq_le #t #l len n
else
begin
FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t);
calc (==) {
Seq.index (nat_to_intseq_le #t #l (len - 1) (n / modulus t)) (i - 1);
== { index_nat_to_intseq_le #t #l (len - 1) (n / modulus t) (i - 1) }
uint ((n / modulus t) / pow2 (bits t * (i - 1)) % modulus t);
== { Math.Lemmas.division_multiplication_lemma n (modulus t) (pow2 (bits t * (i - 1))) }
uint ((n / (pow2 (bits t) * pow2 (bits t * (i - 1)))) % modulus t);
== { Math.Lemmas.pow2_plus (bits t) (bits t * (i - 1)) }
uint ((n / pow2 (bits t + bits t * (i - 1))) % modulus t);
== { Math.Lemmas.distributivity_add_right (bits t) i (-1) }
uint (n / pow2 (bits t + (bits t * i - bits t)) % modulus t);
== { }
uint (n / pow2 (bits t * i) % pow2 (bits t));
};
nat_to_intseq_le_pos #t #l len n
end
let rec index_nat_to_intseq_be #t #l len n i =
if i = 0 then
if len = 0 then () else head_nat_to_intseq_be #t #l len n
else
begin
let len' = len - 1 in
let i' = i - 1 in
let n' = n / pow2 (bits t) in
FStar.Math.Lemmas.lemma_div_lt_nat n (bits t * len) (bits t);
calc (==) {
Seq.index (nat_to_intseq_be #t #l len' n') (len' - i' - 1);
== {index_nat_to_intseq_be #t #l len' n' i'}
uint (n' / pow2 (bits t * i') % pow2 (bits t));
== {}
uint (n / pow2 (bits t) / pow2 (bits t * i') % pow2 (bits t));
== {Math.Lemmas.division_multiplication_lemma n (pow2 (bits t)) (pow2 (bits t * i'))}
uint (n / (pow2 (bits t) * pow2 (bits t * i')) % pow2 (bits t));
== {Math.Lemmas.pow2_plus (bits t) (bits t * i')}
uint (n / (pow2 (bits t + bits t * i')) % pow2 (bits t));
== {Math.Lemmas.distributivity_add_right (bits t) 1 (i - 1)}
uint (n / (pow2 (bits t * i)) % pow2 (bits t));
};
nat_to_intseq_be_pos #t #l len n
end
let uint_to_bytes_le #t #l n =
nat_to_bytes_le (numbytes t) (v n)
let index_uint_to_bytes_le #t #l u =
Classical.forall_intro (index_nat_to_intseq_le #U8 #l (numbytes t) (v u))
let uint_to_bytes_be #t #l n =
nat_to_bytes_be (numbytes t) (v n)
let index_uint_to_bytes_be #t #l u =
Classical.forall_intro (index_nat_to_intseq_be #U8 #l (numbytes t) (v u))
let uint_from_bytes_le #t #l b =
let n = nat_from_intseq_le #U8 b in
uint #t #l n
let uint_from_bytes_be #t #l b =
let n = nat_from_intseq_be #U8 b in
uint #t #l n
val uints_to_bytes_le_inner: #t:inttype{unsigned t} -> #l:secrecy_level
-> #len:size_nat{len * numbytes t < pow2 32}
-> lseq (int_t t l) len
-> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t))
let uints_to_bytes_le_inner #t #l #len b i () =
let open Lib.Sequence in
(), uint_to_bytes_le #t #l b.[i]
let uints_to_bytes_le #t #l #len ul =
let a_spec (i:nat{i <= len}) = unit in
let _, o = generate_blocks (numbytes t) len len a_spec
(uints_to_bytes_le_inner #t #l #len ul) () in
o
(* Could also be written more simply as:
let uints_to_bytes_le #t #l #len ul =
createi (len * numbytes t)
(fun i -> let s = uint_to_bytes_le ul.[i / numbytes t] in
s.[i % numbytes t])
*)
let index_uints_to_bytes_le #t #l #len ul i =
index_generate_blocks (numbytes t) len len (uints_to_bytes_le_inner #t #l #len ul) i
val uints_to_bytes_be_inner: #t:inttype{unsigned t} -> #l:secrecy_level
-> #len:size_nat{len * numbytes t < pow2 32}
-> lseq (int_t t l) len
-> i:nat{i < len} -> unit -> unit & (lseq (uint_t U8 l) (numbytes t))
let uints_to_bytes_be_inner #t #l #len b i () =
let open Lib.Sequence in
(), uint_to_bytes_be #t #l b.[i]
let uints_to_bytes_be #t #l #len ul =
let a_spec (i:nat{i <= len}) = unit in
let _, o = generate_blocks (numbytes t) len len a_spec
(uints_to_bytes_be_inner #t #l #len ul) () in
o
let index_uints_to_bytes_be #t #l #len ul i =
index_generate_blocks (numbytes t) len len (uints_to_bytes_be_inner #t #l #len ul) i
let uints_from_bytes_le #t #l #len b =
Lib.Sequence.createi #(int_t t l) len
(fun i -> uint_from_bytes_le (sub b (i * numbytes t) (numbytes t)))
let index_uints_from_bytes_le #t #l #len b i = ()
let uints_from_bytes_be #t #l #len b =
Lib.Sequence.createi #(int_t t l) len
(fun i -> uint_from_bytes_be (sub b (i * numbytes t) (numbytes t)))
let index_uints_from_bytes_be #t #l #len b i = ()
let uint_at_index_le #t #l #len b i =
uint_from_bytes_le (sub b (i * numbytes t) (numbytes t))
let uint_at_index_be #t #l #len b i =
uint_from_bytes_be (sub b (i * numbytes t) (numbytes t))
#push-options "--max_fuel 1"
val nat_from_intseq_slice_lemma_aux: len:pos -> a:nat -> b:nat -> c:nat -> i:pos{i <= len} ->
Lemma (pow2 ((i - 1) * c) * (a + pow2 c * b) == pow2 ((i - 1) * c) * a + pow2 (i * c) * b)
let nat_from_intseq_slice_lemma_aux len a b c i =
FStar.Math.Lemmas.distributivity_add_right (pow2 ((i - 1) * c)) a (pow2 c * b);
FStar.Math.Lemmas.paren_mul_right (pow2 ((i - 1) * c)) (pow2 c) b;
FStar.Math.Lemmas.pow2_plus ((i - 1) * c) c
val nat_from_intseq_le_slice_lemma_:
#t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat
-> b:lseq (int_t t l) len
-> i:nat{i <= len} ->
Lemma (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 i) + pow2 (i * bits t) * nat_from_intseq_le_ (slice b i len))
let rec nat_from_intseq_le_slice_lemma_ #t #l #len b i =
if len = 0 then ()
else begin
if i = 0 then ()
else begin
let b1 = slice b 0 i in
nat_from_intseq_le_slice_lemma_ #t #l #i b1 (i - 1);
assert (nat_from_intseq_le_ b1 == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * v b.[i - 1]);
nat_from_intseq_le_slice_lemma_ #t #l #len b (i - 1);
assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (i - 1)) + pow2 ((i - 1) * bits t) * nat_from_intseq_le_ (slice b (i - 1) len));
nat_from_intseq_slice_lemma_aux len (v b.[i - 1]) (nat_from_intseq_le_ (slice b i len)) (bits t) i
end
end
let nat_from_intseq_le_lemma0 #t #l b = ()
let nat_from_intseq_le_slice_lemma #t #l #len b i =
nat_from_intseq_le_slice_lemma_ b i
val nat_from_intseq_be_slice_lemma_:
#t:inttype{unsigned t} -> #l:secrecy_level -> #len:size_nat
-> b:lseq (int_t t l) len
-> i:nat{i <= len} ->
Lemma (ensures (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b i len) + pow2 ((len - i) * bits t) * nat_from_intseq_be_ (slice b 0 i)))
(decreases (len - i))
let rec nat_from_intseq_be_slice_lemma_ #t #l #len b i =
if len = 0 then ()
else begin
if i = len then ()
else begin
let b1 = slice b i len in
nat_from_intseq_be_slice_lemma_ #t #l #(len - i) b1 1;
assert (nat_from_intseq_be_ b1 == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * v b.[i]);
nat_from_intseq_be_slice_lemma_ #t #l #len b (i + 1);
assert (nat_from_intseq_be_ b == nat_from_intseq_be_ (slice b (i + 1) len) + pow2 ((len - i - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (i + 1)));
nat_from_intseq_slice_lemma_aux len (v b.[i]) (nat_from_intseq_be_ (slice b 0 i)) (bits t) (len - i)
end
end
let nat_from_intseq_be_lemma0 #t #l b = ()
#pop-options
let nat_from_intseq_be_slice_lemma #t #l #len b i =
nat_from_intseq_be_slice_lemma_ #t #l #len b i
val uints_from_bytes_le_slice_lemma_lp:
#t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} ->
Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k ==
uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t)))
let uints_from_bytes_le_slice_lemma_lp #t #l #len b i j k =
let r = slice (uints_from_bytes_le #t #l #len b) i j in
index_uints_from_bytes_le #t #l #len b (i + k);
assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t)))
val uints_from_bytes_le_slice_lemma_rp:
#t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} ->
Lemma (index (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k ==
uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t)))
let uints_from_bytes_le_slice_lemma_rp #t #l #len b i j k =
let b1 = slice b (i * numbytes t) (j * numbytes t) in
let r = uints_from_bytes_le #t #l #(j-i) b1 in
index_uints_from_bytes_le #t #l #(j-i) b1 k;
assert (r.[k] == uint_from_bytes_le (sub b1 (k * numbytes t) (numbytes t)));
assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t)))
let uints_from_bytes_le_slice_lemma #t #l #len b i j =
FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_lp #t #l #len b i j);
FStar.Classical.forall_intro (uints_from_bytes_le_slice_lemma_rp #t #l #len b i j);
eq_intro (slice (uints_from_bytes_le #t #l #len b) i j) (uints_from_bytes_le #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t)))
#push-options "--max_fuel 1"
val uints_from_bytes_le_nat_lemma_aux:
#t:inttype{unsigned t /\ ~(U1? t)}
-> #l:secrecy_level
-> #len:size_pos{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t) ->
Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) ==
nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) *
nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))))
let uints_from_bytes_le_nat_lemma_aux #t #l #len b =
let r = uints_from_bytes_le #t #l #len b in
assert (nat_from_intseq_le_ r == v r.[0] + pow2 (bits t) * nat_from_intseq_le_ (slice r 1 len));
assert (nat_from_intseq_le_ (slice b 0 (numbytes t)) == v r.[0]);
uints_from_bytes_le_slice_lemma #t #l #len b 1 len;
assert (slice r 1 len == uints_from_bytes_le #t #l #(len-1) (slice b (numbytes t) (len * numbytes t)))
val uints_from_bytes_le_nat_lemma_:
#t:inttype{unsigned t /\ ~(U1? t)}
-> #l:secrecy_level
-> #len:size_nat{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t) ->
Lemma (nat_from_intseq_le_ (uints_from_bytes_le #t #l #len b) == nat_from_intseq_le_ b)
let rec uints_from_bytes_le_nat_lemma_ #t #l #len b =
if len = 0 then ()
else begin
let b1 = slice b (numbytes t) (len * numbytes t) in
nat_from_intseq_le_slice_lemma_ #U8 #l #(len * numbytes t) b (numbytes t);
assert (nat_from_intseq_le_ b == nat_from_intseq_le_ (slice b 0 (numbytes t)) + pow2 (bits t) * nat_from_intseq_le_ b1);
uints_from_bytes_le_nat_lemma_ #t #l #(len - 1) b1;
assert (nat_from_intseq_le_ (uints_from_bytes_le #t #l #(len - 1) b1) == nat_from_intseq_le_ b1);
uints_from_bytes_le_nat_lemma_aux #t #l #len b
end
let uints_from_bytes_le_nat_lemma #t #l #len b =
uints_from_bytes_le_nat_lemma_ #t #l #len b
val uints_from_bytes_be_slice_lemma_lp:
#t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} -> k:nat{k < j - i} ->
Lemma (index (slice (uints_from_bytes_le #t #l #len b) i j) k ==
uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t)))
let uints_from_bytes_be_slice_lemma_lp #t #l #len b i j k =
let r = slice (uints_from_bytes_le #t #l #len b) i j in
index_uints_from_bytes_be #t #l #len b (i + k);
assert (r.[k] == uint_from_bytes_le (sub b ((i + k) * numbytes t) (numbytes t)))
val uints_from_bytes_be_slice_lemma_rp:
#t:inttype{unsigned t /\ ~(U1? t)}
-> #l:secrecy_level
-> #len:size_pos{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t)
-> i:nat
-> j:nat{i <= j /\ j <= len}
-> k:nat{k < j - i} ->
Lemma (index (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t))) k ==
uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t)))
let uints_from_bytes_be_slice_lemma_rp #t #l #len b i j k =
let b1 = slice b (i * numbytes t) (j * numbytes t) in
let r = uints_from_bytes_be #t #l #(j-i) b1 in
index_uints_from_bytes_be #t #l #(j-i) b1 k;
assert (r.[k] == uint_from_bytes_be (sub b1 (k * numbytes t) (numbytes t)));
assert (r.[k] == uint_from_bytes_be (sub b ((i + k) * numbytes t) (numbytes t)))
val uints_from_bytes_be_slice_lemma: #t:inttype{unsigned t /\ ~(U1? t)} -> #l:secrecy_level -> #len:size_pos{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t) -> i:nat -> j:nat{i <= j /\ j <= len} ->
Lemma (slice (uints_from_bytes_be #t #l #len b) i j == uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t)))
let uints_from_bytes_be_slice_lemma #t #l #len b i j =
FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_lp #t #l #len b i j);
FStar.Classical.forall_intro (uints_from_bytes_be_slice_lemma_rp #t #l #len b i j);
eq_intro (slice (uints_from_bytes_be #t #l #len b) i j) (uints_from_bytes_be #t #l #(j-i) (slice b (i * numbytes t) (j * numbytes t)))
val uints_from_bytes_be_nat_lemma_aux:
#t:inttype{unsigned t /\ ~(U1? t)}
-> #l:secrecy_level
-> #len:size_pos{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t) ->
Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) ==
nat_from_intseq_be (uints_from_bytes_be #t #l #(len-1) (slice b (numbytes t) (len * numbytes t))) + pow2 ((len - 1) * bits t) * nat_from_intseq_be_ (slice b 0 (numbytes t)))
let uints_from_bytes_be_nat_lemma_aux #t #l #len b =
let r = uints_from_bytes_be #t #l #len b in
uints_from_bytes_be_slice_lemma #t #l #len b 1 len;
nat_from_intseq_be_slice_lemma r 1;
assert (nat_from_intseq_be_ r == nat_from_intseq_be (slice r 1 len) + pow2 ((len - 1) * bits t) * uint_v r.[0])
val uints_from_bytes_be_nat_lemma_:
#t:inttype{unsigned t /\ ~(U1? t)}
-> #l:secrecy_level
-> #len:size_nat{len * numbytes t < pow2 32}
-> b:lbytes_l l (len * numbytes t) ->
Lemma (nat_from_intseq_be_ (uints_from_bytes_be #t #l #len b) == nat_from_intseq_be_ b)
let rec uints_from_bytes_be_nat_lemma_ #t #l #len b =
if len = 0 then ()
else begin
uints_from_bytes_be_nat_lemma_aux #t #l #len b;
nat_from_intseq_be_slice_lemma_ b (numbytes t);
uints_from_bytes_be_nat_lemma_ #t #l #(len - 1) (slice b (numbytes t) (len * numbytes t))
end
let uints_from_bytes_be_nat_lemma #t #l #len b =
uints_from_bytes_be_nat_lemma_ #t #l #len b
#pop-options
val index_uints_to_bytes_le_aux:
#t:inttype{unsigned t /\ ~(U1? t)}
-> #l:secrecy_level
-> len:nat{len * numbytes t < pow2 32}
-> n:nat{n < pow2 (bits t * len)}
-> i:nat{i < len * numbytes t}
-> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_le #t #l len n in
Seq.index (uints_to_bytes_le #t #l #len s) i ==
Seq.index (nat_to_bytes_le #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t))
let index_uints_to_bytes_le_aux #t #l len n i =
let open Lib.Sequence in
let s: lseq (int_t t l) len = nat_to_intseq_le #t #l len n in
index_generate_blocks (numbytes t) len len
(uints_to_bytes_le_inner #t #l #len s) i
val index_uints_to_bytes_be_aux:
#t:inttype{unsigned t /\ ~(U1? t)}
-> #l:secrecy_level
-> len:nat{len * numbytes t < pow2 32}
-> n:nat{n < pow2 (bits t * len)}
-> i:nat{i < len * numbytes t}
-> Lemma (let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in
Seq.index (uints_to_bytes_be #t #l #len s) i ==
Seq.index (nat_to_bytes_be #l (numbytes t) (v s.[i / numbytes t])) (i % numbytes t))
let index_uints_to_bytes_be_aux #t #l len n i =
let open Lib.Sequence in
let s:lseq (int_t t l) len = nat_to_intseq_be #t #l len n in
index_generate_blocks (numbytes t) len len
(uints_to_bytes_be_inner #t #l #len s) i
val modulo_pow2_prop: r:pos -> a:nat -> b:nat -> c:nat{c < b} -> Lemma
((a % pow2 (r * b) / pow2 (r * c)) % pow2 r == (a / pow2 (r * c)) % pow2 r)
let modulo_pow2_prop r a b c =
calc (==) {
((a % pow2 (r * b)) / pow2 (r * c)) % pow2 r;
== { Math.Lemmas.pow2_modulo_division_lemma_1 a (r * c) (r * b) }
((a / pow2 (r * c) % pow2 (r * b - r * c))) % pow2 r;
== { Math.Lemmas.lemma_mul_sub_distr r b c }
((a / pow2 (r * c) % pow2 (r * (b - c)))) % pow2 r;
== { Math.Lemmas.pow2_plus r (r * (b - c) - r) }
(a / pow2 (r * c)) % (pow2 r * pow2 (r * (b - c) - r)) % pow2 r;
== { Math.Lemmas.modulo_modulo_lemma (a / pow2 (r * c)) (pow2 r) (pow2 (r * (b - c) - r))}
(a / pow2 (r * c)) % pow2 r;
}
val some_arithmetic: t:inttype{~(U1? t)} -> n:nat -> i:nat -> Lemma
(let m = numbytes t in
n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8 ==
n / pow2 (8 * i) % pow2 8) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.ByteSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"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
}
] | {
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Lib.IntTypes.inttype{~(U1? t)} -> n: Prims.nat -> i: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(let m = Lib.IntTypes.numbytes t in
n / Prims.pow2 (Lib.IntTypes.bits t * (i / m)) % Prims.pow2 (Lib.IntTypes.bits t) /
Prims.pow2 (8 * (i % m)) %
Prims.pow2 8 ==
n / Prims.pow2 (8 * i) % Prims.pow2 8)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_U1",
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.pow2",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims._assert",
"Prims.squash",
"FStar.Math.Lemmas.euclidean_division_definition",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.distributivity_sub_right",
"Lib.ByteSequence.modulo_pow2_prop",
"FStar.Math.Lemmas.division_multiplication_lemma",
"FStar.Math.Lemmas.pow2_plus",
"Lib.IntTypes.numbytes"
] | [] | false | false | true | false | false | let some_arithmetic t n i =
| let m = numbytes t in
calc ( == ) {
n / pow2 (bits t * (i / m)) % pow2 (bits t) / pow2 (8 * (i % m)) % pow2 8;
( == ) { assert (bits t == 8 * m) }
n / pow2 ((8 * m) * (i / m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8;
( == ) { (FStar.Math.Lemmas.paren_mul_right 8 m (i / m);
FStar.Math.Lemmas.euclidean_division_definition i m) }
n / pow2 (8 * (i - i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8;
( == ) { Math.Lemmas.distributivity_sub_right 8 i (i % m) }
n / pow2 (8 * i - 8 * (i % m)) % pow2 (8 * m) / pow2 (8 * (i % m)) % pow2 8;
( == ) { modulo_pow2_prop 8 (n / pow2 (8 * i - 8 * (i % m))) m (i % m) }
(n / pow2 (8 * i - 8 * (i % m))) / pow2 (8 * (i % m)) % pow2 8;
( == ) { Math.Lemmas.division_multiplication_lemma n
(pow2 (8 * i - 8 * (i % m)))
(pow2 (8 * (i % m))) }
(n / (pow2 (8 * i - 8 * (i % m)) * pow2 (8 * (i % m)))) % pow2 8;
( == ) { Math.Lemmas.pow2_plus (8 * i - 8 * (i % m)) (8 * (i % m)) }
(n / pow2 (8 * i)) % pow2 8;
} | false |
Trace.fst | Trace.cutlast | val cutlast (l: list 'a {length l > 0}) : list 'a * 'a | val cutlast (l: list 'a {length l > 0}) : list 'a * 'a | let rec cutlast (l : list 'a{length l > 0}) : list 'a * 'a =
match l with
| [x] -> [], x
| x::xs -> let ys, y = cutlast xs in x::ys, y | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 121,
"start_col": 0,
"start_line": 118
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z)
let cons_fst_qn = ["Trace"; "cons_fst"]
let term_is_fv hd nm : Tac bool =
match inspect hd with
| Tv_FVar fv -> inspect_fv fv = inspect_fv nm
| _ -> false
noeq
type ins_info = {
orig_name : fv;
ins_name : fv;
args : (args : list term{length args <= 8});
trace_arg : term;
}
let rec instrument_body (ii : ins_info) (t : term) : Tac term =
match inspect_unascribe t with
// descend into matches
| Tv_Match t ret_opt brs -> begin
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
end
// descend into lets
| Tv_Let r attrs b t1 t2 -> begin
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
end
| _ -> begin
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then begin
// modify the tail call
// turn `nm <b1,...,bn>` into `nm' (<a1,...,an>::tr) <b1,...,bn>`
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
end else begin
// not a tail call, record the current set of args and be done
mkpair (mk_cons argpack ii.trace_arg) t
end
end
and ins_br (ii : ins_info) (br : branch) : Tac branch =
let (p, t) = br in
let t' = instrument_body ii t in
(p, t') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | l: Prims.list 'a {FStar.List.Tot.Base.length l > 0} -> Prims.list 'a * 'a | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.List.Tot.Base.length",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"Trace.cutlast"
] | [
"recursion"
] | false | false | false | false | false | let rec cutlast (l: list 'a {length l > 0}) : list 'a * 'a =
| match l with
| [x] -> [], x
| x :: xs ->
let ys, y = cutlast xs in
x :: ys, y | false |
Trace.fst | Trace.fall | val fall (n: mynat) : Tot mynat | val fall (n: mynat) : Tot mynat | let rec fall (n : mynat) : Tot mynat =
match n with
| Z -> Z
| S n -> fall n | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 158,
"start_col": 0,
"start_line": 155
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z)
let cons_fst_qn = ["Trace"; "cons_fst"]
let term_is_fv hd nm : Tac bool =
match inspect hd with
| Tv_FVar fv -> inspect_fv fv = inspect_fv nm
| _ -> false
noeq
type ins_info = {
orig_name : fv;
ins_name : fv;
args : (args : list term{length args <= 8});
trace_arg : term;
}
let rec instrument_body (ii : ins_info) (t : term) : Tac term =
match inspect_unascribe t with
// descend into matches
| Tv_Match t ret_opt brs -> begin
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
end
// descend into lets
| Tv_Let r attrs b t1 t2 -> begin
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
end
| _ -> begin
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then begin
// modify the tail call
// turn `nm <b1,...,bn>` into `nm' (<a1,...,an>::tr) <b1,...,bn>`
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
end else begin
// not a tail call, record the current set of args and be done
mkpair (mk_cons argpack ii.trace_arg) t
end
end
and ins_br (ii : ins_info) (br : branch) : Tac branch =
let (p, t) = br in
let t' = instrument_body ii t in
(p, t')
let rec cutlast (l : list 'a{length l > 0}) : list 'a * 'a =
match l with
| [x] -> [], x
| x::xs -> let ys, y = cutlast xs in x::ys, y
let instrument (f : 'a) : Tac unit =
let t = quote f in
// name
let n = match inspect t with
| Tv_FVar fv -> fv
| _ -> fail "Not a top-level"
in
let n' = tick n in
let all_args = intros () in
if length all_args = 0 then
fail "Function has no arguments?";
let real, trace_arg = cutlast all_args in
let real = map (fun b -> pack (Tv_Var (binding_to_namedv b))) real in
if length real > 8 then
fail "Too many arguments to instrument function";
assert (length real <= 8);
let ii = {
orig_name = n;
ins_name = n';
args = real;
trace_arg = pack (Tv_Var (binding_to_namedv trace_arg))
} in
(* Apply the function to the arguments and unfold it. This will only
* unfold it once, so recursive calls are present *)
let t = norm_term [delta; zeta] (mk_e_app t ii.args) in
dup ();
let t = instrument_body ii t in
(* dump ""; *)
let _ = focus (fun () -> exact_guard t; repeat smt) in
norm [];
trefl () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | n: Trace.mynat -> Trace.mynat | Prims.Tot | [
"total"
] | [] | [
"Trace.mynat",
"Trace.Z",
"Trace.fall"
] | [
"recursion"
] | false | false | false | true | false | let rec fall (n: mynat) : Tot mynat =
| match n with
| Z -> Z
| S n -> fall n | false |
FStar.UInt.fst | FStar.UInt.lemma_lognot_value_mod | val lemma_lognot_value_mod: #n:pos -> a:uint_t n ->
Lemma
(requires True)
(ensures (lognot a = pow2 n - a - 1))
(decreases n) | val lemma_lognot_value_mod: #n:pos -> a:uint_t n ->
Lemma
(requires True)
(ensures (lognot a = pow2 n - a - 1))
(decreases n) | let rec lemma_lognot_value_mod #n a =
if n = 1 then () else
begin
assert (-pow2 n <= (-(a+1)) && -(a+1) < 0);
let av = to_vec a in
let hd = from_vec #1 (Seq.slice (to_vec a) 0 1) in
let tl = from_vec #(n-1) (Seq.slice (to_vec a) 1 n) in
assert (hd = 0 || hd = 1);
let hdpow = op_Multiply hd (pow2 (n-1)) in
from_vec_propriety (to_vec a) 1;
assert (from_vec av = (op_Multiply
(from_vec #1 (Seq.slice av 0 1)) (pow2 (n-1))) +
(from_vec #(n-1) (Seq.slice av 1 n)));
let ntl = lognot tl in
lemma_lognot_value_mod #(n-1) tl;
assert (ntl = pow2 (n-1) - tl - 1);
assert (a = hdpow + tl);
assert (lognot a = lognot #n (hdpow + tl));
assert (tl < pow2 (n-1));
if hdpow = 0 then
begin
assert (lognot a = lognot #n tl);
lemma_lognot_zero_ext #(n-1) tl;
lemma_zero_extend tl
end
else
begin
lemma_lognot_one_ext #(n-1) tl;
lemma_one_extend tl
end
end | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 7,
"end_line": 550,
"start_col": 0,
"start_line": 515
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a)
#push-options "--z3rlimit 40"
let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a)
#pop-options
#push-options "--fuel 1 --ifuel 0 --z3rlimit 40"
let lemma_lognot_zero_ext #n a =
let lhs = lognot #(n+1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n+1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n+1) eav = from_vec #n av);
assert (from_vec #(n+1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n+1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n+1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i:pos{i < n+1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs)
let lemma_lognot_one_ext #n a =
let lhs = lognot #(n+1) (one_extend a) in
let rhs = lognot #n a in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot #n a) in
let eav = Seq.append hd1 av in
append_lemma #1 #n hd1 av;
append_lemma #1 #n hd0 nav;
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd0 nav in
Seq.Base.lemma_eq_elim neav_l neav_r | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"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": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n
-> FStar.Pervasives.Lemma (ensures FStar.UInt.lognot a = Prims.pow2 n - a - 1) (decreases n) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.UInt.lemma_zero_extend",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.UInt.lemma_lognot_zero_ext",
"Prims._assert",
"Prims.b2t",
"FStar.UInt.lognot",
"FStar.UInt.lemma_one_extend",
"FStar.UInt.lemma_lognot_one_ext",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Addition",
"FStar.UInt.lemma_lognot_value_mod",
"FStar.UInt.from_vec",
"Prims.op_Multiply",
"FStar.Seq.Base.slice",
"FStar.UInt.from_vec_propriety",
"FStar.UInt.to_vec",
"Prims.op_BarBar",
"FStar.BitVector.bv_t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_Minus"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_lognot_value_mod #n a =
| if n = 1
then ()
else
(assert (- pow2 n <= (- (a + 1)) && - (a + 1) < 0);
let av = to_vec a in
let hd = from_vec #1 (Seq.slice (to_vec a) 0 1) in
let tl = from_vec #(n - 1) (Seq.slice (to_vec a) 1 n) in
assert (hd = 0 || hd = 1);
let hdpow = op_Multiply hd (pow2 (n - 1)) in
from_vec_propriety (to_vec a) 1;
assert (from_vec av =
(op_Multiply (from_vec #1 (Seq.slice av 0 1)) (pow2 (n - 1))) +
(from_vec #(n - 1) (Seq.slice av 1 n)));
let ntl = lognot tl in
lemma_lognot_value_mod #(n - 1) tl;
assert (ntl = pow2 (n - 1) - tl - 1);
assert (a = hdpow + tl);
assert (lognot a = lognot #n (hdpow + tl));
assert (tl < pow2 (n - 1));
if hdpow = 0
then
(assert (lognot a = lognot #n tl);
lemma_lognot_zero_ext #(n - 1) tl;
lemma_zero_extend tl)
else
(lemma_lognot_one_ext #(n - 1) tl;
lemma_one_extend tl)) | false |
FStar.UInt.fst | FStar.UInt.lemma_lognot_value_zero | val lemma_lognot_value_zero: #n:pos -> a:uint_t n{a = 0} ->
Lemma (lognot a = sub_mod (sub_mod 0 a) 1) | val lemma_lognot_value_zero: #n:pos -> a:uint_t n{a = 0} ->
Lemma (lognot a = sub_mod (sub_mod 0 a) 1) | let lemma_lognot_value_zero #n a =
let p = pow2 n in
calc (==) {
sub_mod (sub_mod 0 a) 1;
== { }
sub_mod ((0 - a) % p) 1;
== { }
((0 - a) % p - 1) % p;
== { }
(0 % p - 1) % p;
== { modulo_lemma 0 p }
(0 - 1) % p;
== { lemma_mod_sub_0 p }
p - 1;
== { }
p - 0 - 1;
== { lemma_lognot_value_mod a }
lognot a;
} | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 571,
"start_col": 0,
"start_line": 553
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1)
#push-options "--z3rlimit 50"
let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s)
#pop-options
let shift_right_value_lemma #n a s =
if s >= n then shift_right_value_aux_1 #n a s
else if s = 0 then shift_right_value_aux_2 #n a
else shift_right_value_aux_3 #n a s
let lemma_msb_pow2 #n a = if n = 1 then () else from_vec_propriety (to_vec a) 1
val plus_one_mod : p:pos -> a:nat ->
Lemma (requires (a < p /\ ((a + 1) % p == 0))) (ensures (a == p - 1))
let plus_one_mod p a = ()
let lemma_minus_zero #n a =
if minus a = 0 then
begin
plus_one_mod (pow2 n) (lognot a);
lognot_self a;
logxor_self (ones n);
logxor_lemma_2 #n (ones n)
end
#push-options "--z3rlimit 20 --fuel 1 --ifuel 0"
let lemma_msb_gte #n a b =
from_vec_propriety (to_vec a) 1;
from_vec_propriety (to_vec b) 1
#pop-options
(* Lemmas toward showing ~n + 1 = -a *)
// #set-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
#push-options "--z3rlimit 80"
let lemma_uint_mod #n a = ()
#pop-options
let lemma_add_sub_cancel #n a b =
let ab = (a-b) % pow2 n in
let abb = (ab + b) % pow2 n in
let ab_mod = sub_mod a b in
let abb_mod = add_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
assert (add_mod (sub_mod a b) b = add_mod ab_mod b);
assert (add_mod ab_mod b = (ab_mod + b) % p);
assert (add_mod ab_mod b = ((a-b) % p + b) % p);
FStar.Math.Lemmas.lemma_mod_plus_distr_l (a-b) b p;
assert (((a-b) + b) % p = (((a-b) % p) + b) % p);
assert (a % p = (((a-b) % p) + b) % p)
let lemma_mod_sub_distr_l a b p =
let q = (a - (a % p)) / p in
FStar.Math.Lemmas.lemma_mod_spec2 a p;
FStar.Math.Lemmas.lemma_mod_plus (a % p - b) q p
let lemma_sub_add_cancel #n a b =
let ab = (a+b) % pow2 n in
let abb = (ab - b) % pow2 n in
let ab_mod = add_mod a b in
let abb_mod = sub_mod ab b in
let p = pow2 n in
lemma_uint_mod a;
lemma_mod_sub_distr_l (a+b) b p
let lemma_zero_extend #n a =
let hd0 = Seq.create 1 false in
let av = to_vec a in
let eav = Seq.append hd0 av in
let r = zero_extend a in
append_lemma #1 #n hd0 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = a)
#push-options "--z3rlimit 40"
let lemma_one_extend #n a =
let hd1 = Seq.create 1 true in
let av = to_vec a in
let eav = Seq.append hd1 av in
let r = one_extend a in
append_lemma #1 #n hd1 av;
assert (r = from_vec eav);
from_vec_propriety #(n+1) eav 1;
assert (r = pow2 n + a)
#pop-options
#push-options "--fuel 1 --ifuel 0 --z3rlimit 40"
let lemma_lognot_zero_ext #n a =
let lhs = lognot #(n+1) a in
let rhs = pow2 n + (lognot #n a) in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot a) in
let eav = Seq.append hd0 av in
append_lemma #1 #n hd0 av;
assert (from_vec #(n+1) eav = op_Multiply (from_vec #1 hd0) (pow2 n) + from_vec av);
assert (op_Multiply (from_vec #1 hd0) (pow2 n) = 0);
assert (from_vec #(n+1) eav = from_vec #n av);
assert (from_vec #(n+1) eav < pow2 n);
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd1 nav in
append_lemma #1 #n hd1 nav;
assert (from_vec #(n+1) neav_l = (op_Multiply (from_vec #1 hd1) (pow2 n)) + (from_vec #n nav));
assert (op_Multiply (from_vec #1 hd1) (pow2 n) = pow2 n);
assert (from_vec #(n+1) neav_l = pow2 n + from_vec #n nav);
assert (pow2 n + from_vec #n nav = rhs);
assert (forall (i:pos{i < n+1}). Seq.index neav_r i = Seq.index neav_l i);
Seq.Base.lemma_eq_intro neav_l neav_r;
assert (neav_l = neav_r);
assert (from_vec neav_r = lhs)
let lemma_lognot_one_ext #n a =
let lhs = lognot #(n+1) (one_extend a) in
let rhs = lognot #n a in
let av = to_vec a in
assert (Seq.length av = n);
let hd0 = Seq.create 1 false in
let hd1 = Seq.create 1 true in
let nav = to_vec (lognot #n a) in
let eav = Seq.append hd1 av in
append_lemma #1 #n hd1 av;
append_lemma #1 #n hd0 nav;
let nav = BitVector.lognot_vec #n av in
let neav_r = BitVector.lognot_vec #(n+1) eav in
let neav_l = Seq.append hd0 nav in
Seq.Base.lemma_eq_elim neav_l neav_r
#push-options "--z3rlimit 60"
let rec lemma_lognot_value_mod #n a =
if n = 1 then () else
begin
assert (-pow2 n <= (-(a+1)) && -(a+1) < 0);
let av = to_vec a in
let hd = from_vec #1 (Seq.slice (to_vec a) 0 1) in
let tl = from_vec #(n-1) (Seq.slice (to_vec a) 1 n) in
assert (hd = 0 || hd = 1);
let hdpow = op_Multiply hd (pow2 (n-1)) in
from_vec_propriety (to_vec a) 1;
assert (from_vec av = (op_Multiply
(from_vec #1 (Seq.slice av 0 1)) (pow2 (n-1))) +
(from_vec #(n-1) (Seq.slice av 1 n)));
let ntl = lognot tl in
lemma_lognot_value_mod #(n-1) tl;
assert (ntl = pow2 (n-1) - tl - 1);
assert (a = hdpow + tl);
assert (lognot a = lognot #n (hdpow + tl));
assert (tl < pow2 (n-1));
if hdpow = 0 then
begin
assert (lognot a = lognot #n tl);
lemma_lognot_zero_ext #(n-1) tl;
lemma_zero_extend tl
end
else
begin
lemma_lognot_one_ext #(n-1) tl;
lemma_one_extend tl
end
end
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"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": 40,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n {a = 0}
-> FStar.Pervasives.Lemma
(ensures FStar.UInt.lognot a = FStar.UInt.sub_mod (FStar.UInt.sub_mod 0 a) 1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Calc.calc_finish",
"Prims.eq2",
"FStar.UInt.sub_mod",
"FStar.UInt.lognot",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.modulo_lemma",
"FStar.Math.Lemmas.lemma_mod_sub_0",
"FStar.UInt.lemma_lognot_value_mod",
"Prims.pow2"
] | [] | false | false | true | false | false | let lemma_lognot_value_zero #n a =
| let p = pow2 n in
calc ( == ) {
sub_mod (sub_mod 0 a) 1;
( == ) { () }
sub_mod ((0 - a) % p) 1;
( == ) { () }
((0 - a) % p - 1) % p;
( == ) { () }
(0 % p - 1) % p;
( == ) { modulo_lemma 0 p }
(0 - 1) % p;
( == ) { lemma_mod_sub_0 p }
p - 1;
( == ) { () }
p - 0 - 1;
( == ) { lemma_lognot_value_mod a }
lognot a;
} | false |
Trace.fst | Trace.instrument | val instrument (f: 'a) : Tac unit | val instrument (f: 'a) : Tac unit | let instrument (f : 'a) : Tac unit =
let t = quote f in
// name
let n = match inspect t with
| Tv_FVar fv -> fv
| _ -> fail "Not a top-level"
in
let n' = tick n in
let all_args = intros () in
if length all_args = 0 then
fail "Function has no arguments?";
let real, trace_arg = cutlast all_args in
let real = map (fun b -> pack (Tv_Var (binding_to_namedv b))) real in
if length real > 8 then
fail "Too many arguments to instrument function";
assert (length real <= 8);
let ii = {
orig_name = n;
ins_name = n';
args = real;
trace_arg = pack (Tv_Var (binding_to_namedv trace_arg))
} in
(* Apply the function to the arguments and unfold it. This will only
* unfold it once, so recursive calls are present *)
let t = norm_term [delta; zeta] (mk_e_app t ii.args) in
dup ();
let t = instrument_body ii t in
(* dump ""; *)
let _ = focus (fun () -> exact_guard t; repeat smt) in
norm [];
trefl () | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 153,
"start_col": 0,
"start_line": 123
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z)
let cons_fst_qn = ["Trace"; "cons_fst"]
let term_is_fv hd nm : Tac bool =
match inspect hd with
| Tv_FVar fv -> inspect_fv fv = inspect_fv nm
| _ -> false
noeq
type ins_info = {
orig_name : fv;
ins_name : fv;
args : (args : list term{length args <= 8});
trace_arg : term;
}
let rec instrument_body (ii : ins_info) (t : term) : Tac term =
match inspect_unascribe t with
// descend into matches
| Tv_Match t ret_opt brs -> begin
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
end
// descend into lets
| Tv_Let r attrs b t1 t2 -> begin
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
end
| _ -> begin
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then begin
// modify the tail call
// turn `nm <b1,...,bn>` into `nm' (<a1,...,an>::tr) <b1,...,bn>`
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
end else begin
// not a tail call, record the current set of args and be done
mkpair (mk_cons argpack ii.trace_arg) t
end
end
and ins_br (ii : ins_info) (br : branch) : Tac branch =
let (p, t) = br in
let t' = instrument_body ii t in
(p, t')
let rec cutlast (l : list 'a{length l > 0}) : list 'a * 'a =
match l with
| [x] -> [], x
| x::xs -> let ys, y = cutlast xs in x::ys, y | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | f: 'a -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.trefl",
"Prims.unit",
"FStar.Stubs.Tactics.V2.Builtins.norm",
"Prims.Nil",
"FStar.Pervasives.norm_step",
"FStar.Tactics.V2.Derived.focus",
"FStar.Tactics.V2.Derived.repeat",
"FStar.Tactics.V2.Derived.smt",
"FStar.Tactics.V2.Derived.exact_guard",
"FStar.Tactics.NamedView.term",
"Trace.instrument_body",
"FStar.Stubs.Tactics.V2.Builtins.dup",
"FStar.Tactics.V2.Derived.norm_term",
"Prims.Cons",
"FStar.Pervasives.delta",
"FStar.Pervasives.zeta",
"FStar.Reflection.V2.Derived.mk_e_app",
"Trace.__proj__Mkins_info__item__args",
"Trace.ins_info",
"Trace.Mkins_info",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_Var",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_namedv",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.List.Tot.Base.length",
"Prims.op_GreaterThan",
"FStar.Tactics.V2.Derived.fail",
"Prims.bool",
"FStar.Tactics.Util.map",
"FStar.Pervasives.Native.tuple2",
"Trace.cutlast",
"Prims.op_Equality",
"Prims.int",
"FStar.Tactics.V2.Derived.intros",
"FStar.Stubs.Reflection.Types.fv",
"Trace.tick",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.inspect",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | true | false | false | false | let instrument (f: 'a) : Tac unit =
| let t = quote f in
let n =
match inspect t with
| Tv_FVar fv -> fv
| _ -> fail "Not a top-level"
in
let n' = tick n in
let all_args = intros () in
if length all_args = 0 then fail "Function has no arguments?";
let real, trace_arg = cutlast all_args in
let real = map (fun b -> pack (Tv_Var (binding_to_namedv b))) real in
if length real > 8 then fail "Too many arguments to instrument function";
assert (length real <= 8);
let ii =
{
orig_name = n;
ins_name = n';
args = real;
trace_arg = pack (Tv_Var (binding_to_namedv trace_arg))
}
in
let t = norm_term [delta; zeta] (mk_e_app t ii.args) in
dup ();
let t = instrument_body ii t in
let _ =
focus (fun () ->
exact_guard t;
repeat smt)
in
norm [];
trefl () | false |
Trace.fst | Trace.fact_aux | val fact_aux (n acc: nat) : Tot nat | val fact_aux (n acc: nat) : Tot nat | let rec fact_aux (n acc : nat) : Tot nat =
if n = 0
then acc
else let acc' = acc `op_Multiply` n in fact_aux (n - 1) acc' | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 64,
"end_line": 177,
"start_col": 0,
"start_line": 174
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z)
let cons_fst_qn = ["Trace"; "cons_fst"]
let term_is_fv hd nm : Tac bool =
match inspect hd with
| Tv_FVar fv -> inspect_fv fv = inspect_fv nm
| _ -> false
noeq
type ins_info = {
orig_name : fv;
ins_name : fv;
args : (args : list term{length args <= 8});
trace_arg : term;
}
let rec instrument_body (ii : ins_info) (t : term) : Tac term =
match inspect_unascribe t with
// descend into matches
| Tv_Match t ret_opt brs -> begin
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
end
// descend into lets
| Tv_Let r attrs b t1 t2 -> begin
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
end
| _ -> begin
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then begin
// modify the tail call
// turn `nm <b1,...,bn>` into `nm' (<a1,...,an>::tr) <b1,...,bn>`
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
end else begin
// not a tail call, record the current set of args and be done
mkpair (mk_cons argpack ii.trace_arg) t
end
end
and ins_br (ii : ins_info) (br : branch) : Tac branch =
let (p, t) = br in
let t' = instrument_body ii t in
(p, t')
let rec cutlast (l : list 'a{length l > 0}) : list 'a * 'a =
match l with
| [x] -> [], x
| x::xs -> let ys, y = cutlast xs in x::ys, y
let instrument (f : 'a) : Tac unit =
let t = quote f in
// name
let n = match inspect t with
| Tv_FVar fv -> fv
| _ -> fail "Not a top-level"
in
let n' = tick n in
let all_args = intros () in
if length all_args = 0 then
fail "Function has no arguments?";
let real, trace_arg = cutlast all_args in
let real = map (fun b -> pack (Tv_Var (binding_to_namedv b))) real in
if length real > 8 then
fail "Too many arguments to instrument function";
assert (length real <= 8);
let ii = {
orig_name = n;
ins_name = n';
args = real;
trace_arg = pack (Tv_Var (binding_to_namedv trace_arg))
} in
(* Apply the function to the arguments and unfold it. This will only
* unfold it once, so recursive calls are present *)
let t = norm_term [delta; zeta] (mk_e_app t ii.args) in
dup ();
let t = instrument_body ii t in
(* dump ""; *)
let _ = focus (fun () -> exact_guard t; repeat smt) in
norm [];
trefl ()
let rec fall (n : mynat) : Tot mynat =
match n with
| Z -> Z
| S n -> fall n
// Because of the way we're building this recursive function, its termination is unprovable.
// So admit queries for now.
#push-options "--admit_smt_queries true"
let rec fall' (n : mynat) (l : list mynat) =
// We need to annotate the result type.. which sucks.
// But we could use a tactic later :)
synth_by_tactic #(mynat -> list mynat -> (list mynat * mynat)) (fun () -> instrument fall) n l
#pop-options
let _ = assert (fall' (S (S (S Z))) [] == ([Z; S Z; S (S Z); S (S (S Z))], Z))
// Beware: the `let acc' = `... gets normalized in the tactic,
// so we're not actually descending through it. Maybe we need a flag | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | n: Prims.nat -> acc: Prims.nat -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Trace.fact_aux",
"Prims.op_Subtraction",
"Prims.op_Multiply"
] | [
"recursion"
] | false | false | false | true | false | let rec fact_aux (n acc: nat) : Tot nat =
| if n = 0
then acc
else
let acc' = acc `op_Multiply` n in
fact_aux (n - 1) acc' | false |
Trace.fst | Trace.fact' | val fact' (n: nat) (tr: list nat) : Tot (list nat * int) | val fact' (n: nat) (tr: list nat) : Tot (list nat * int) | let rec fact' (n : nat) (tr : list nat) : Tot (list nat * int) =
synth_by_tactic #(nat -> list nat -> (list nat * int)) (fun () -> instrument fact) n tr | {
"file_name": "examples/tactics/Trace.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 91,
"end_line": 193,
"start_col": 0,
"start_line": 192
} | (*
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 Trace
open FStar.List.Tot
(* Instrumenting recursive functions to provide a trace of their calls *)
(* TODO: update to make use of metaprogrammed let-recs and splicing *)
(* Do not warn about recursive functions not used in their bodies:
since we metaprogram them, the desugaring phase wrongly concludes
they do not have to be recursive, but they do. *)
#push-options "--warn_error -328"
(* We take a function such as
*
* val fall : mynat -> Tot mynat
* let rec fall (n : mynat) : Tot mynat =
* match n with
* | Z -> Z
* | S n -> fall n
*
* and automatically instrument it to keep a trace of its recursive calls,
* obtaining the definition:
*
* val fall' : mynat -> list mynat -> (list mynat) * mynat
* let rec fall' n t =
* match n with
* | Z -> (n :: t, Z)
* | S n -> fall' n (n :: t)
*
* The trace is taken as the last argument to (hopefully) have less impact over
* termination criteria: having it first would need annotations, since the trace always
* grows.
*
* We don't actually require all recursive calls to be in tail positions, but those
* are the only ones we will detect and instrument. Note that the instrumented function
* is also tail-recursive (and the trace is "backwards").
*)
open FStar.Tactics.V2
type mynat =
| Z
| S of mynat
let rec tick_last (ns:list string) =
match ns with
| [] -> []
| [x] -> [x ^ "'"]
| x::xs -> x :: (tick_last xs)
let tick (nm : fv) : fv =
let ns = inspect_fv nm in
pack_fv (tick_last ns)
let cons_fst (x : 'a) (p : list 'a * 'b) : list 'a * 'b =
let (y, z) = p in (x :: y, z)
let cons_fst_qn = ["Trace"; "cons_fst"]
let term_is_fv hd nm : Tac bool =
match inspect hd with
| Tv_FVar fv -> inspect_fv fv = inspect_fv nm
| _ -> false
noeq
type ins_info = {
orig_name : fv;
ins_name : fv;
args : (args : list term{length args <= 8});
trace_arg : term;
}
let rec instrument_body (ii : ins_info) (t : term) : Tac term =
match inspect_unascribe t with
// descend into matches
| Tv_Match t ret_opt brs -> begin
let brs' = map (ins_br ii) brs in
pack (Tv_Match t ret_opt brs')
end
// descend into lets
| Tv_Let r attrs b t1 t2 -> begin
let t2' = instrument_body ii t2 in
pack (Tv_Let r attrs b t1 t2')
end
| _ -> begin
let hd, args = collect_app t in
let argpack = mktuple_n ii.args in
if term_is_fv hd ii.orig_name
then begin
// modify the tail call
// turn `nm <b1,...,bn>` into `nm' (<a1,...,an>::tr) <b1,...,bn>`
let f' = pack (Tv_FVar ii.ins_name) in
mk_app f' (args @ [mk_cons argpack ii.trace_arg, Q_Explicit])
end else begin
// not a tail call, record the current set of args and be done
mkpair (mk_cons argpack ii.trace_arg) t
end
end
and ins_br (ii : ins_info) (br : branch) : Tac branch =
let (p, t) = br in
let t' = instrument_body ii t in
(p, t')
let rec cutlast (l : list 'a{length l > 0}) : list 'a * 'a =
match l with
| [x] -> [], x
| x::xs -> let ys, y = cutlast xs in x::ys, y
let instrument (f : 'a) : Tac unit =
let t = quote f in
// name
let n = match inspect t with
| Tv_FVar fv -> fv
| _ -> fail "Not a top-level"
in
let n' = tick n in
let all_args = intros () in
if length all_args = 0 then
fail "Function has no arguments?";
let real, trace_arg = cutlast all_args in
let real = map (fun b -> pack (Tv_Var (binding_to_namedv b))) real in
if length real > 8 then
fail "Too many arguments to instrument function";
assert (length real <= 8);
let ii = {
orig_name = n;
ins_name = n';
args = real;
trace_arg = pack (Tv_Var (binding_to_namedv trace_arg))
} in
(* Apply the function to the arguments and unfold it. This will only
* unfold it once, so recursive calls are present *)
let t = norm_term [delta; zeta] (mk_e_app t ii.args) in
dup ();
let t = instrument_body ii t in
(* dump ""; *)
let _ = focus (fun () -> exact_guard t; repeat smt) in
norm [];
trefl ()
let rec fall (n : mynat) : Tot mynat =
match n with
| Z -> Z
| S n -> fall n
// Because of the way we're building this recursive function, its termination is unprovable.
// So admit queries for now.
#push-options "--admit_smt_queries true"
let rec fall' (n : mynat) (l : list mynat) =
// We need to annotate the result type.. which sucks.
// But we could use a tactic later :)
synth_by_tactic #(mynat -> list mynat -> (list mynat * mynat)) (fun () -> instrument fall) n l
#pop-options
let _ = assert (fall' (S (S (S Z))) [] == ([Z; S Z; S (S Z); S (S (S Z))], Z))
// Beware: the `let acc' = `... gets normalized in the tactic,
// so we're not actually descending through it. Maybe we need a flag
// to control the evaluation of lets.
let rec fact_aux (n acc : nat) : Tot nat =
if n = 0
then acc
else let acc' = acc `op_Multiply` n in fact_aux (n - 1) acc'
let fact (n : nat) : Tot nat = fact_aux n 1
#push-options "--admit_smt_queries true"
let rec fact_aux' (n acc : nat) (tr : list (nat * nat)) : Tot (list (nat * nat) * nat) =
synth_by_tactic #(nat -> nat -> list (nat * nat) -> (list (nat * nat) * nat)) (fun () -> instrument fact_aux) n acc tr
#pop-options
let _ = assert (fact_aux' 5 1 [] == ([(0, 120); (1, 120); (2, 60); (3, 20); (4, 5); (5, 1)], 120))
(* We can also instrument `fact`, but we won't get anything too
* interesting as that's not the tail-recursive function *)
#push-options "--admit_smt_queries true" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Trace.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | n: Prims.nat -> tr: Prims.list Prims.nat -> Prims.list Prims.nat * Prims.int | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.list",
"Prims.op_Equality",
"Prims.int",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Cons",
"Prims.bool",
"Trace.fact_aux",
"Prims.op_Subtraction",
"Prims.op_Multiply",
"FStar.Pervasives.Native.tuple2"
] | [
"recursion"
] | false | false | false | true | false | let rec fact' (n: nat) (tr: list nat) : Tot (list nat * int) =
| synth_by_tactic #(nat -> list nat -> (list nat * int)) (fun () -> instrument fact) n tr | false |
Steel.ST.SeqMatch.fst | Steel.ST.SeqMatch.seq_list_match_cons_intro | val seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a': t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> v': t'{v' << a' :: v} -> vprop))
: STGhostT unit
opened
((item_match a a') `star` (seq_list_match c v item_match))
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match) | val seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a': t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> v': t'{v' << a' :: v} -> vprop))
: STGhostT unit
opened
((item_match a a') `star` (seq_list_match c v item_match))
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match) | let seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a' : t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << a' :: v }) -> vprop))
: STGhostT unit opened
(item_match a a' `star` seq_list_match c v item_match)
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match)
= seq_list_match_cons_eq (Seq.cons a c) (a' :: v) item_match;
noop ();
rewrite
(seq_list_match_cons0 (Seq.cons a c) (a' :: v) item_match seq_list_match)
(seq_list_match (Seq.cons a c) (a' :: v) item_match) | {
"file_name": "lib/steel/Steel.ST.SeqMatch.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 105,
"start_col": 0,
"start_line": 90
} | module Steel.ST.SeqMatch
include Steel.ST.OnRange
open Steel.ST.GenElim
module Seq = FStar.Seq
module SZ = FStar.SizeT
(* `seq_list_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a list of high-level
values. `seq_list_match` is carefully designed to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values. *)
[@@__reduce__]
let seq_list_match_nil0
(#t: Type)
(c: Seq.seq t)
: Tot vprop
= pure (c `Seq.equal` Seq.empty)
[@@__reduce__]
let seq_list_match_cons0
(#t #t': Type)
(c: Seq.seq t)
(l: list t' { Cons? l })
(item_match: (t -> (v': t' { v' << l }) -> vprop))
(seq_list_match: (Seq.seq t -> (v': list t') -> (raw_data_item_match: (t -> (v'': t' { v'' << v' }) -> vprop) { v' << l }) ->
vprop))
: Tot vprop
= exists_ (fun (c1: t) -> exists_ (fun (c2: Seq.seq t) ->
item_match c1 (List.Tot.hd l) `star`
seq_list_match c2 (List.Tot.tl l) item_match `star`
pure (c `Seq.equal` Seq.cons c1 c2)
))
let rec seq_list_match
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Tot vprop
(decreases v)
= if Nil? v
then seq_list_match_nil0 c
else seq_list_match_cons0 c v item_match seq_list_match
let seq_list_match_cons_eq
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Lemma
(requires (Cons? v))
(ensures (
seq_list_match c v item_match ==
seq_list_match_cons0 c v item_match seq_list_match
))
= let a :: q = v in
assert_norm (seq_list_match c (a :: q) item_match ==
seq_list_match_cons0 c (a :: q) item_match seq_list_match
)
let seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhost unit opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\
Nil? v)
(fun _ -> True)
= noop ();
rewrite
(seq_list_match_nil0 c)
(seq_list_match c v item_match)
let list_cons_precedes
(#t: Type)
(a: t)
(q: list t)
: Lemma
((a << a :: q) /\ (q << a :: q))
[SMTPat (a :: q)]
= assert (List.Tot.hd (a :: q) << (a :: q));
assert (List.Tot.tl (a :: q) << (a :: q)) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.OnRange.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Steel.ST.SeqMatch.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.OnRange",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
a: t ->
a': t' ->
c: FStar.Seq.Base.seq t ->
v: Prims.list t' ->
item_match: (_: t -> v': t'{v' << a' :: v} -> Steel.Effect.Common.vprop)
-> Steel.ST.Effect.Ghost.STGhostT Prims.unit | Steel.ST.Effect.Ghost.STGhostT | [] | [] | [
"Steel.Memory.inames",
"FStar.Seq.Base.seq",
"Prims.list",
"Prims.precedes",
"Prims.Cons",
"Steel.Effect.Common.vprop",
"Steel.ST.Util.rewrite",
"Steel.ST.SeqMatch.seq_list_match_cons0",
"FStar.Seq.Base.cons",
"Steel.ST.SeqMatch.seq_list_match",
"Prims.unit",
"Steel.ST.Util.noop",
"Steel.ST.SeqMatch.seq_list_match_cons_eq",
"Steel.Effect.Common.star"
] | [] | false | true | false | false | false | let seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a': t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> v': t'{v' << a' :: v} -> vprop))
: STGhostT unit
opened
((item_match a a') `star` (seq_list_match c v item_match))
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match) =
| seq_list_match_cons_eq (Seq.cons a c) (a' :: v) item_match;
noop ();
rewrite (seq_list_match_cons0 (Seq.cons a c) (a' :: v) item_match seq_list_match)
(seq_list_match (Seq.cons a c) (a' :: v) item_match) | false |
CQueue.fst | CQueue.llist_fragment_head_append | val llist_fragment_head_append
(#opened: _)
(#a: Type)
(l1: Ghost.erased (list a))
(phead1: ref (ccell_ptrvalue a))
(head1: ccell_ptrvalue a)
(l2: Ghost.erased (list a))
(phead2: ref (ccell_ptrvalue a))
(head2: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (list a))
opened
((llist_fragment_head l1 phead1 head1) `star` (llist_fragment_head l2 phead2 head2))
(fun l -> llist_fragment_head l phead1 head1)
(fun h ->
sel_llist_fragment_head l1 phead1 head1 h == (Ghost.reveal phead2, Ghost.reveal head2))
(fun h l h' ->
Ghost.reveal l == (Ghost.reveal l1) `L.append` (Ghost.reveal l2) /\
h' (llist_fragment_head l phead1 head1) == h (llist_fragment_head l2 phead2 head2))
(decreases (Ghost.reveal l1)) | val llist_fragment_head_append
(#opened: _)
(#a: Type)
(l1: Ghost.erased (list a))
(phead1: ref (ccell_ptrvalue a))
(head1: ccell_ptrvalue a)
(l2: Ghost.erased (list a))
(phead2: ref (ccell_ptrvalue a))
(head2: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (list a))
opened
((llist_fragment_head l1 phead1 head1) `star` (llist_fragment_head l2 phead2 head2))
(fun l -> llist_fragment_head l phead1 head1)
(fun h ->
sel_llist_fragment_head l1 phead1 head1 h == (Ghost.reveal phead2, Ghost.reveal head2))
(fun h l h' ->
Ghost.reveal l == (Ghost.reveal l1) `L.append` (Ghost.reveal l2) /\
h' (llist_fragment_head l phead1 head1) == h (llist_fragment_head l2 phead2 head2))
(decreases (Ghost.reveal l1)) | let rec llist_fragment_head_append
(#opened: _)
(#a: Type)
(l1: Ghost.erased (list a))
(phead1: ref (ccell_ptrvalue a))
(head1: ccell_ptrvalue a)
(l2: Ghost.erased (list a))
(phead2: ref (ccell_ptrvalue a))
(head2: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_head l1 phead1 head1 `star` llist_fragment_head l2 phead2 head2)
(fun l -> llist_fragment_head l phead1 head1)
(fun h -> sel_llist_fragment_head l1 phead1 head1 h == (Ghost.reveal phead2, Ghost.reveal head2))
(fun h l h' ->
Ghost.reveal l == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
h' (llist_fragment_head l phead1 head1) == h (llist_fragment_head l2 phead2 head2)
)
(decreases (Ghost.reveal l1))
=
if Nil? l1
then begin
elim_llist_fragment_head_nil l1 phead1 head1;
change_equal_slprop
(llist_fragment_head l2 phead2 head2)
(llist_fragment_head l2 phead1 head1);
l2
end else begin
let u = elim_llist_fragment_head_cons l1 phead1 head1 in
let head1' : Ghost.erased (ccell_lvalue a) = head1 in
let l3 = llist_fragment_head_append u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next l2 phead2 head2 in
change_equal_slprop
(llist_fragment_head l3 u.ll_uncons_pnext u.ll_uncons_next)
(llist_fragment_head l3 (ccell_next head1') u.ll_uncons_next);
change_equal_slprop
(ccell head1)
(ccell head1');
let l4 = intro_llist_fragment_head_cons phead1 head1' u.ll_uncons_next l3 in
change_equal_slprop
(llist_fragment_head l4 phead1 head1')
(llist_fragment_head l4 phead1 head1);
l4
end | {
"file_name": "share/steel/examples/steel/CQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 981,
"start_col": 0,
"start_line": 940
} | module CQueue
open CQueue.LList
#set-options "--ide_id_info_off"
//Re-define squash, since this module explicitly
//replies on proving equalities of the form `t_of v == squash p`
//which are delicate in the presence of optimizations that
//unfold `Prims.squash (p /\ q)`to _:unit{p /\ q}
//See Issue #2496
let squash (p:Type u#a) : Type0 = squash p
(* BEGIN library *)
let intro_vrewrite_no_norm (#opened:inames)
(v: vprop) (#t: Type) (f: (t_of v) -> GTot t)
: SteelGhost unit opened v (fun _ -> vrewrite v f)
(fun _ -> True) (fun h _ h' -> h' (vrewrite v f) == f (h v))
=
intro_vrewrite v f
let elim_vrewrite_no_norm (#opened:inames)
(v: vprop)
(#t: Type)
(f: ((t_of v) -> GTot t))
: SteelGhost unit opened (vrewrite v f) (fun _ -> v)
(fun _ -> True)
(fun h _ h' -> h (vrewrite v f) == f (h' v))
=
elim_vrewrite v f
let vconst_sel
(#a: Type)
(x: a)
: Tot (selector a (hp_of emp))
= fun _ -> x
[@@ __steel_reduce__]
let vconst'
(#a: Type)
(x: a)
: GTot vprop'
= {
hp = hp_of emp;
t = a;
sel = vconst_sel x;
}
[@@ __steel_reduce__]
let vconst (#a: Type) (x: a) : Tot vprop = VUnit (vconst' x)
let intro_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
emp
(fun _ -> vconst x)
(fun _ -> True)
(fun _ _ h' -> h' (vconst x) == x)
=
change_slprop_rel
emp
(vconst x)
(fun _ y -> y == x)
(fun _ -> ())
let elim_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
(vconst x)
(fun _ -> emp)
(fun _ -> True)
(fun h _ _ -> h (vconst x) == x)
=
change_slprop_rel
(vconst x)
emp
(fun y _ -> y == x)
(fun _ -> ())
let vpure_sel'
(p: prop)
: Tot (selector' (squash p) (Steel.Memory.pure p))
= fun (m: Steel.Memory.hmem (Steel.Memory.pure p)) -> pure_interp p m
let vpure_sel
(p: prop)
: Tot (selector (squash p) (Steel.Memory.pure p))
= vpure_sel' p
[@@ __steel_reduce__]
let vpure'
(p: prop)
: GTot vprop'
= {
hp = Steel.Memory.pure p;
t = squash p;
sel = vpure_sel p;
}
[@@ __steel_reduce__]
let vpure (p: prop) : Tot vprop = VUnit (vpure' p)
let intro_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
emp
(fun _ -> vpure p)
(fun _ -> p)
(fun _ _ h' -> p)
=
change_slprop_rel
emp
(vpure p)
(fun _ _ -> p)
(fun m -> pure_interp p m)
let elim_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
(vpure p)
(fun _ -> emp)
(fun _ -> True)
(fun _ _ _ -> p)
=
change_slprop_rel
(vpure p)
emp
(fun _ _ -> p)
(fun m -> pure_interp p m; reveal_emp (); intro_emp m)
val intro_vdep2 (#opened:inames)
(v: vprop)
(q: vprop)
(x: t_of v)
(p: (t_of v -> Tot vprop))
: SteelGhost unit opened
(v `star` q)
(fun _ -> vdep v p)
(requires (fun h ->
q == p x /\
x == h v
))
(ensures (fun h _ h' ->
let x2 = h' (vdep v p) in
q == p (h v) /\
dfst x2 == (h v) /\
dsnd x2 == (h q)
))
let intro_vdep2
v q x p
=
intro_vdep v q p
let vbind0_payload
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: t_of a)
: Tot vprop
= vpure (t == t_of (b x)) `star` b x
let vbind0_rewrite
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: normal (t_of (vdep a (vbind0_payload a t b))))
: Tot t
= snd (dsnd x)
[@@__steel_reduce__; __reduce__]
let vbind0
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= a `vdep` vbind0_payload a t b `vrewrite` vbind0_rewrite a t b
let vbind_hp // necessary to hide the attribute on hp_of
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot (slprop u#1)
= hp_of (vbind0 a t b)
let vbind_sel // same for hp_sel
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot (selector t (vbind_hp a t b))
= sel_of (vbind0 a t b)
[@@__steel_reduce__]
let vbind'
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot vprop'
= {
hp = vbind_hp a t b;
t = t;
sel = vbind_sel a t b;
}
[@@__steel_reduce__]
let vbind
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= VUnit (vbind' a t b)
let intro_vbind
(#opened: _)
(a: vprop)
(b' : vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost unit opened
(a `star` b')
(fun _ -> vbind a t b)
(fun h -> t_of b' == t /\ b' == b (h a))
(fun h _ h' ->
t_of b' == t /\
b' == b (h a) /\
h' (vbind a t b) == h b'
)
=
intro_vpure (t == t_of b');
intro_vdep
a
(vpure (t == t_of b') `star` b')
(vbind0_payload a t b);
intro_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
change_slprop_rel
(vbind0 a t b)
(vbind a t b)
(fun x y -> x == y)
(fun _ -> ())
let elim_vbind
(#opened: _)
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a)) opened
(vbind a t b)
(fun res -> a `star` b (Ghost.reveal res))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\
t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)
)
=
change_slprop_rel
(vbind a t b)
(vbind0 a t b)
(fun x y -> x == y)
(fun _ -> ());
elim_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
let res = elim_vdep a (vbind0_payload a t b) in
change_equal_slprop
(vbind0_payload a t b (Ghost.reveal res))
(vpure (t == t_of (b (Ghost.reveal res))) `star` b (Ghost.reveal res));
elim_vpure (t == t_of (b (Ghost.reveal res)));
res
let (==) (#a:_) (x y: a) : prop = x == y
let snoc_inj (#a: Type) (hd1 hd2: list a) (tl1 tl2: a) : Lemma
(requires (hd1 `L.append` [tl1] == hd2 `L.append` [tl2]))
(ensures (hd1 == hd2 /\ tl1 == tl2))
[SMTPat (hd1 `L.append` [tl1]); SMTPat (hd2 `L.append` [tl2])]
= L.lemma_snoc_unsnoc (hd1, tl1);
L.lemma_snoc_unsnoc (hd2, tl2)
[@"opaque_to_smt"]
let unsnoc (#a: Type) (l: list a) : Pure (list a & a)
(requires (Cons? l))
(ensures (fun (hd, tl) -> l == hd `L.append` [tl] /\ L.length hd < L.length l))
=
L.lemma_unsnoc_snoc l;
L.append_length (fst (L.unsnoc l)) [snd (L.unsnoc l)];
L.unsnoc l
let unsnoc_hd (#a: Type) (l: list a) : Pure (list a) (requires (Cons? l)) (ensures (fun l' -> L.length l' <
L.length l)) = fst (unsnoc l)
let unsnoc_tl (#a: Type) (l: list a) : Pure (a) (requires (Cons? l)) (ensures (fun _ -> True)) = snd (unsnoc l)
[@@"opaque_to_smt"]
let snoc (#a: Type) (l: list a) (x: a) : Pure (list a)
(requires True)
(ensures (fun l' ->
Cons? l' /\
unsnoc_hd l' == l /\
unsnoc_tl l' == x
))
=
let l' = L.snoc (l, x) in
L.append_length l [x];
snoc_inj l (unsnoc_hd l') x (unsnoc_tl l');
l'
let snoc_unsnoc
(#a: Type)
(l: list a)
: Lemma
(requires (Cons? l))
(ensures (snoc (unsnoc_hd l) (unsnoc_tl l) == l))
= ()
unfold
let coerce
(#a: Type)
(x: a)
(b: Type)
: Pure b
(requires (a == b))
(ensures (fun y -> a == b /\ x == y))
= x
(* END library *)
let t a = cllist_lvalue a
let v (a: Type0) = list a
let datas
(#a: Type0)
(l: v a)
: Tot (list a)
= l
(* view from the tail *)
let llist_fragment_tail_cons_data_refine
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(d: a)
: Tot prop
= d == unsnoc_tl (Ghost.reveal l)
[@@ __steel_reduce__]
let llist_fragment_tail_cons_lvalue_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(c: ccell_lvalue a)
: Tot vprop
= vptr (ccell_data c) `vrefine` llist_fragment_tail_cons_data_refine l
let ccell_is_lvalue_refine
(a: Type)
(c: ccell_ptrvalue a)
: Tot prop
= ccell_ptrvalue_is_null c == false
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_next_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(ptail: ref (ccell_ptrvalue a))
: Tot vprop
= vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_rewrite
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(llist_fragment_tail: vprop { t_of llist_fragment_tail == ref (ccell_ptrvalue a) })
(x: normal (t_of (llist_fragment_tail `vdep` (llist_fragment_tail_cons_next_payload l))))
: Tot (ref (ccell_ptrvalue a))
= let (| _, (| c, _ |) |) = x in
ccell_next c
let rec llist_fragment_tail (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : Pure vprop
(requires True)
(ensures (fun v -> t_of v == ref (ccell_ptrvalue a)))
(decreases (Ghost.reveal (L.length l)))
= if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
let llist_fragment_tail_eq
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
= assert_norm
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
let llist_fragment_tail_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(requires (Cons? l))
(ensures (Cons? l /\
llist_fragment_tail l phead == (
llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
)))
= llist_fragment_tail_eq l phead
unfold
let sel_llist_fragment_tail
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_tail l phead) /\ True) })
: GTot (ref (ccell_ptrvalue a))
=
coerce (h (llist_fragment_tail l phead)) (ref (ccell_ptrvalue a))
val intro_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_tail l phead)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_tail l phead h' == phead)
let intro_llist_fragment_tail_nil
l phead
=
intro_vconst phead;
change_equal_slprop
(vconst phead)
(llist_fragment_tail l phead)
val elim_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l phead)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_tail l phead h == phead)
let elim_llist_fragment_tail_nil
l phead
=
change_equal_slprop
(llist_fragment_tail l phead)
(vconst phead);
elim_vconst phead
val intro_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(ptail: Ghost.erased (ref (ccell_ptrvalue a)))
(tail: Ghost.erased (ccell_lvalue a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l phead `star` vptr ptail `star` vptr (ccell_data tail))
(fun res -> llist_fragment_tail res phead)
(fun h ->
sel_llist_fragment_tail l phead h == Ghost.reveal ptail /\
sel ptail h == Ghost.reveal tail
)
(fun h res h' ->
Ghost.reveal res == snoc (Ghost.reveal l) (sel (ccell_data tail) h) /\
sel_llist_fragment_tail res phead h' == ccell_next tail
)
#push-options "--z3rlimit 16"
let intro_llist_fragment_tail_snoc
#_ #a l phead ptail tail
=
let d = gget (vptr (ccell_data tail)) in
let l' : (l' : Ghost.erased (list a) { Cons? (Ghost.reveal l') }) = Ghost.hide (snoc (Ghost.reveal l) (Ghost.reveal d)) in
intro_vrefine (vptr (ccell_data tail)) (llist_fragment_tail_cons_data_refine l');
intro_vrefine (vptr ptail) (ccell_is_lvalue_refine a);
intro_vdep
(vptr ptail `vrefine` ccell_is_lvalue_refine a)
(vptr (ccell_data tail) `vrefine` llist_fragment_tail_cons_data_refine l')
(llist_fragment_tail_cons_lvalue_payload l');
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead);
intro_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead)
(vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l')
(llist_fragment_tail_cons_next_payload l');
intro_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l')
(llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead));
llist_fragment_tail_eq_cons l' phead;
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l' `vrewrite` llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead))
(llist_fragment_tail l' phead);
let g' = gget (llist_fragment_tail l' phead) in
assert (Ghost.reveal g' == ccell_next tail);
noop ();
l'
#pop-options
[@@erasable]
noeq
type ll_unsnoc_t (a: Type) = {
ll_unsnoc_l: list a;
ll_unsnoc_ptail: ref (ccell_ptrvalue a);
ll_unsnoc_tail: ccell_lvalue a;
}
val elim_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost (ll_unsnoc_t a) opened
(llist_fragment_tail l phead)
(fun res -> llist_fragment_tail res.ll_unsnoc_l phead `star` vptr res.ll_unsnoc_ptail `star` vptr (ccell_data res.ll_unsnoc_tail))
(fun _ -> Cons? l)
(fun h res h' ->
Cons? l /\
Ghost.reveal res.ll_unsnoc_l == unsnoc_hd l /\
sel res.ll_unsnoc_ptail h' == res.ll_unsnoc_tail /\
sel (ccell_data res.ll_unsnoc_tail) h'== unsnoc_tl l /\
sel_llist_fragment_tail res.ll_unsnoc_l phead h' == res.ll_unsnoc_ptail /\
sel_llist_fragment_tail l phead h == (ccell_next res.ll_unsnoc_tail)
)
#push-options "--z3rlimit 32"
#restart-solver
let elim_llist_fragment_tail_snoc
#_ #a l phead
=
let l0 : (l0: Ghost.erased (list a) { Cons? l0 }) = Ghost.hide (Ghost.reveal l) in
llist_fragment_tail_eq_cons l0 phead;
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0 `vrewrite` llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
elim_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0)
(llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
let ptail = elim_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail_cons_next_payload l0)
in
let ptail0 : Ghost.erased (ref (ccell_ptrvalue a)) = ptail in
change_equal_slprop
(llist_fragment_tail_cons_next_payload l0 (Ghost.reveal ptail))
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l0);
let tail = elim_vdep
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a)
(llist_fragment_tail_cons_lvalue_payload l0)
in
elim_vrefine (vptr (Ghost.reveal ptail0)) (ccell_is_lvalue_refine a);
let res = {
ll_unsnoc_l = unsnoc_hd l0;
ll_unsnoc_ptail = Ghost.reveal ptail0;
ll_unsnoc_tail = Ghost.reveal tail;
} in
change_equal_slprop
(vptr (Ghost.reveal ptail0))
(vptr res.ll_unsnoc_ptail);
change_equal_slprop
(llist_fragment_tail_cons_lvalue_payload l0 (Ghost.reveal tail))
(vptr (ccell_data res.ll_unsnoc_tail) `vrefine` llist_fragment_tail_cons_data_refine l0);
elim_vrefine
(vptr (ccell_data res.ll_unsnoc_tail))
(llist_fragment_tail_cons_data_refine l0);
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail res.ll_unsnoc_l phead);
res
#pop-options
let rec llist_fragment_tail_append
(#opened: _)
(#a: Type)
(phead0: ref (ccell_ptrvalue a))
(l1: Ghost.erased (list a))
(phead1: Ghost.erased (ref (ccell_ptrvalue a)))
(l2: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l1 phead0 `star` llist_fragment_tail l2 phead1)
(fun res -> llist_fragment_tail res phead0)
(fun h ->
Ghost.reveal phead1 == (sel_llist_fragment_tail l1 phead0) h
)
(fun h res h' ->
Ghost.reveal res == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
(sel_llist_fragment_tail res phead0) h' == (sel_llist_fragment_tail l2 phead1) h
)
(decreases (L.length (Ghost.reveal l2)))
=
let g1 = gget (llist_fragment_tail l1 phead0) in
assert (Ghost.reveal phead1 == Ghost.reveal g1);
if Nil? l2
then begin
L.append_l_nil (Ghost.reveal l1);
elim_llist_fragment_tail_nil l2 phead1;
l1
end else begin
let res = elim_llist_fragment_tail_snoc l2 (Ghost.reveal phead1) in
let d = gget (vptr (ccell_data res.ll_unsnoc_tail)) in
L.append_assoc (Ghost.reveal l1) (Ghost.reveal res.ll_unsnoc_l) [Ghost.reveal d];
let l3 = llist_fragment_tail_append phead0 l1 phead1 res.ll_unsnoc_l in
intro_llist_fragment_tail_snoc l3 phead0 res.ll_unsnoc_ptail res.ll_unsnoc_tail
end
let queue_tail_refine
(#a: Type)
(tail1: ref (ccell_ptrvalue a))
(tail2: ref (ccell_ptrvalue a))
(tl: normal (t_of (vptr tail2)))
: Tot prop
= ccell_ptrvalue_is_null tl == true /\ tail1 == tail2
[@@__steel_reduce__]
let queue_tail_dep2
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
(tail2: ref (ccell_ptrvalue a))
: Tot vprop
= vptr tail2 `vrefine` queue_tail_refine tail1 tail2
[@@__steel_reduce__]
let queue_tail_dep1
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
: Tot vprop
= vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail1
[@@__steel_reduce__; __reduce__]
let queue_tail
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: Tot vprop
=
llist_fragment_tail l (cllist_head x) `vdep` queue_tail_dep1 x l
val intro_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun _ -> queue_tail x l)
(fun h ->
sel_llist_fragment_tail l (cllist_head x) h == tail /\
sel (cllist_tail x) h == tail /\
ccell_ptrvalue_is_null (sel tail h)
)
(fun _ _ _ -> True)
let intro_queue_tail
x l tail
=
intro_vrefine (vptr tail) (queue_tail_refine tail tail);
intro_vdep2
(vptr (cllist_tail x))
(vptr tail `vrefine` queue_tail_refine tail tail)
tail
(queue_tail_dep2 x l tail);
intro_vdep2
(llist_fragment_tail l (cllist_head x))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail)
tail
(queue_tail_dep1 x l)
val elim_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened
(queue_tail x l)
(fun tail -> llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun h -> True)
(fun _ tail h ->
sel_llist_fragment_tail l (cllist_head x) h == Ghost.reveal tail /\
sel (cllist_tail x) h == Ghost.reveal tail /\
ccell_ptrvalue_is_null (h (vptr tail))
)
let elim_queue_tail
#_ #a x l
=
let tail0 = elim_vdep
(llist_fragment_tail l (cllist_head x))
(queue_tail_dep1 x l)
in
let tail : Ghost.erased (ref (ccell_ptrvalue a)) = tail0 in
change_equal_slprop
(queue_tail_dep1 x l (Ghost.reveal tail0))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail0);
let tail2 = elim_vdep
(vptr (cllist_tail x))
(queue_tail_dep2 x l tail0)
in
let tail3 : Ghost.erased (ref (ccell_ptrvalue a)) = tail2 in
change_equal_slprop
(queue_tail_dep2 x l tail0 (Ghost.reveal tail2))
(vptr tail3 `vrefine` queue_tail_refine tail0 tail3);
elim_vrefine (vptr tail3) (queue_tail_refine tail0 tail3);
change_equal_slprop
(vptr tail3)
(vptr tail);
tail
(* view from the head *)
let llist_fragment_head_data_refine
(#a: Type)
(d: a)
(c: vcell a)
: Tot prop
= c.vcell_data == d
let llist_fragment_head_payload
(#a: Type)
(head: ccell_ptrvalue a)
(d: a)
(llist_fragment_head: (ref (ccell_ptrvalue a) -> ccell_ptrvalue a -> Tot vprop))
(x: t_of (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine d)))
: Tot vprop
=
llist_fragment_head (ccell_next (fst x)) (snd x).vcell_next
let rec llist_fragment_head (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : Tot vprop
(decreases (Ghost.reveal l))
=
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
let t_of_llist_fragment_head
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(t_of (llist_fragment_head l phead head) == ref (ccell_ptrvalue a) & ccell_ptrvalue a)
= ()
unfold
let sel_llist_fragment_head
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_head l phead head) /\ True) })
: GTot (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
=
coerce (h (llist_fragment_head l phead head)) (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
val intro_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_head l phead head)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_head l phead head h' == (phead, head))
let intro_llist_fragment_head_nil
l phead head
=
intro_vconst (phead, head);
change_equal_slprop
(vconst (phead, head))
(llist_fragment_head l phead head)
val elim_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_head l phead head h == (phead, head))
let elim_llist_fragment_head_nil
l phead head
=
change_equal_slprop
(llist_fragment_head l phead head)
(vconst (phead, head));
elim_vconst (phead, head)
let llist_fragment_head_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(requires (Cons? (Ghost.reveal l)))
(ensures (
llist_fragment_head l phead head ==
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
= assert_norm
(llist_fragment_head l phead head == (
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
val intro_llist_fragment_head_cons
(#opened: _)
(#a: Type) (phead: ref (ccell_ptrvalue a)) (head: ccell_lvalue a) (next: (ccell_ptrvalue a)) (tl: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(ccell head `star` llist_fragment_head tl (ccell_next head) next)
(fun res -> llist_fragment_head res phead head)
(fun h -> (h (ccell head)).vcell_next == next)
(fun h res h' ->
Ghost.reveal res == (h (ccell head)).vcell_data :: Ghost.reveal tl /\
h' (llist_fragment_head res phead head) == h (llist_fragment_head tl (ccell_next head) next)
)
let intro_llist_fragment_head_cons
#_ #a phead head next tl
=
let vc = gget (ccell head) in
let l' : (l' : Ghost.erased (list a) { Cons? l' }) = Ghost.hide (vc.vcell_data :: tl) in
intro_ccell_is_lvalue head;
intro_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l'));
intro_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(llist_fragment_head tl (ccell_next head) next)
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l')));
llist_fragment_head_eq_cons l' phead head;
change_equal_slprop
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l'))))
(llist_fragment_head l' phead head);
l'
[@@erasable]
noeq
type ll_uncons_t
(a: Type)
= {
ll_uncons_pnext: Ghost.erased (ref (ccell_ptrvalue a));
ll_uncons_next: Ghost.erased (ccell_ptrvalue a);
ll_uncons_tl: Ghost.erased (list a);
}
val elim_llist_fragment_head_cons
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (ll_uncons_t a) opened
(llist_fragment_head l phead head)
(fun res -> ccell head `star` llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next)
(fun _ -> Cons? (Ghost.reveal l))
(fun h res h' ->
ccell_ptrvalue_is_null head == false /\
Ghost.reveal l == (h' (ccell head)).vcell_data :: Ghost.reveal res.ll_uncons_tl /\
Ghost.reveal res.ll_uncons_pnext == ccell_next head /\
Ghost.reveal res.ll_uncons_next == (h' (ccell head)).vcell_next /\
h' (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) == h (llist_fragment_head l phead head)
)
let elim_llist_fragment_head_cons
#_ #a l0 phead head
=
let l : (l : Ghost.erased (list a) { Cons? l }) = l0 in
change_equal_slprop
(llist_fragment_head l0 phead head)
(llist_fragment_head l phead head);
llist_fragment_head_eq_cons l phead head;
change_equal_slprop
(llist_fragment_head l phead head)
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l))));
let x = elim_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)))
in
let head2 = gget (ccell_is_lvalue head) in
elim_ccell_is_lvalue head;
elim_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l));
let vhead2 = gget (ccell head) in
let res = {
ll_uncons_pnext = ccell_next head2;
ll_uncons_next = vhead2.vcell_next;
ll_uncons_tl = L.tl l;
} in
change_equal_slprop
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)) (Ghost.reveal x))
(llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next);
res | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"CQueue.LList.fsti.checked"
],
"interface_file": true,
"source_file": "CQueue.fst"
} | [
{
"abbrev": false,
"full_module": "CQueue.LList",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
l1: FStar.Ghost.erased (Prims.list a) ->
phead1: Steel.Reference.ref (CQueue.Cell.ccell_ptrvalue a) ->
head1: CQueue.Cell.ccell_ptrvalue a ->
l2: FStar.Ghost.erased (Prims.list a) ->
phead2: Steel.Reference.ref (CQueue.Cell.ccell_ptrvalue a) ->
head2: CQueue.Cell.ccell_ptrvalue a
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased (Prims.list a)) | Steel.Effect.Atomic.SteelGhost | [
""
] | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Prims.list",
"Steel.Reference.ref",
"CQueue.Cell.ccell_ptrvalue",
"Prims.uu___is_Nil",
"FStar.Ghost.reveal",
"Prims.unit",
"Steel.Effect.Atomic.change_equal_slprop",
"CQueue.llist_fragment_head",
"CQueue.elim_llist_fragment_head_nil",
"Prims.bool",
"CQueue.Cell.ccell_lvalue",
"CQueue.intro_llist_fragment_head_cons",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_next",
"CQueue.Cell.ccell",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_pnext",
"CQueue.Cell.ccell_next",
"CQueue.llist_fragment_head_append",
"CQueue.__proj__Mkll_uncons_t__item__ll_uncons_tl",
"FStar.Ghost.hide",
"CQueue.ll_uncons_t",
"CQueue.elim_llist_fragment_head_cons",
"Steel.Effect.Common.star",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"CQueue.op_Equals_Equals",
"FStar.Pervasives.Native.tuple2",
"CQueue.sel_llist_fragment_head",
"FStar.Pervasives.Native.Mktuple2",
"Prims.l_and",
"FStar.List.Tot.Base.append",
"Steel.Effect.Common.normal",
"Steel.Effect.Common.t_of"
] | [
"recursion"
] | false | true | false | false | false | let rec llist_fragment_head_append
(#opened: _)
(#a: Type)
(l1: Ghost.erased (list a))
(phead1: ref (ccell_ptrvalue a))
(head1: ccell_ptrvalue a)
(l2: Ghost.erased (list a))
(phead2: ref (ccell_ptrvalue a))
(head2: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (list a))
opened
((llist_fragment_head l1 phead1 head1) `star` (llist_fragment_head l2 phead2 head2))
(fun l -> llist_fragment_head l phead1 head1)
(fun h ->
sel_llist_fragment_head l1 phead1 head1 h == (Ghost.reveal phead2, Ghost.reveal head2))
(fun h l h' ->
Ghost.reveal l == (Ghost.reveal l1) `L.append` (Ghost.reveal l2) /\
h' (llist_fragment_head l phead1 head1) == h (llist_fragment_head l2 phead2 head2))
(decreases (Ghost.reveal l1)) =
| if Nil? l1
then
(elim_llist_fragment_head_nil l1 phead1 head1;
change_equal_slprop (llist_fragment_head l2 phead2 head2) (llist_fragment_head l2 phead1 head1);
l2)
else
let u = elim_llist_fragment_head_cons l1 phead1 head1 in
let head1':Ghost.erased (ccell_lvalue a) = head1 in
let l3 =
llist_fragment_head_append u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next l2 phead2 head2
in
change_equal_slprop (llist_fragment_head l3 u.ll_uncons_pnext u.ll_uncons_next)
(llist_fragment_head l3 (ccell_next head1') u.ll_uncons_next);
change_equal_slprop (ccell head1) (ccell head1');
let l4 = intro_llist_fragment_head_cons phead1 head1' u.ll_uncons_next l3 in
change_equal_slprop (llist_fragment_head l4 phead1 head1') (llist_fragment_head l4 phead1 head1);
l4 | false |
FStar.UInt.fst | FStar.UInt.shift_right_value_aux_3 | val shift_right_value_aux_3: #n:pos -> a:uint_t n -> s:pos{s < n} ->
Lemma (requires True)
(ensures shift_right #n a s = a / pow2 s) | val shift_right_value_aux_3: #n:pos -> a:uint_t n -> s:pos{s < n} ->
Lemma (requires True)
(ensures shift_right #n a s = a / pow2 s) | let shift_right_value_aux_3 #n a s =
append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s) | {
"file_name": "ulib/FStar.UInt.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 379,
"start_col": 0,
"start_line": 377
} | (*
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.UInt
(* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| 128 -> assert_norm (pow2 128 = 0x100000000000000000000000000000000)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
#push-options "--fuel 0 --ifuel 0"
let lt_square_div_lt a b = ()
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
#pop-options
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom a b; ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let rec to_vec_lemma_2 #n a b =
if n = 0 then () else begin
assert(equal (slice (to_vec b) 0 (n - 1)) (to_vec #(n - 1) (b / 2)));
assert(equal (slice (to_vec a) 0 (n - 1)) (to_vec #(n - 1) (a / 2)));
to_vec_lemma_2 #(n - 1) (a / 2) (b / 2);
assert(a % 2 = (if index (to_vec a) (n - 1) then 1 else 0));
assert(b % 2 = (if index (to_vec b) (n - 1) then 1 else 0));
assert(a % 2 = b % 2)
end
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = to_vec_lemma_2 #n num (from_vec (to_vec num))
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
#push-options "--fuel 0 --ifuel 0"
let from_vec_aux #n a s1 s2 =
paren_mul_left (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
paren_mul_right (from_vec #s2 (slice a 0 s2)) (pow2 (s1 - s2)) (pow2 (n - s1));
pow2_plus (s1 - s2) (n - s1)
#pop-options
let seq_slice_lemma #n a s1 t1 s2 t2 = ()
#push-options "--initial_fuel 1 --max_fuel 1"
let rec from_vec_propriety #n a s =
if s = n - 1 then () else begin
from_vec_propriety #n a (s + 1);
from_vec_propriety #(s + 1) (slice a 0 (s + 1)) s;
seq_slice_lemma #n a 0 (s + 1) 0 s;
seq_slice_lemma #n a 0 (s + 1) s (s + 1);
from_vec_aux #n a (s + 1) s;
from_vec_propriety #(n - s) (slice a s n) 1;
seq_slice_lemma #n a s n 0 1;
seq_slice_lemma #n a s n 1 (n - s)
end
#pop-options
let append_lemma #n #m a b =
assert(equal a (slice (append a b) 0 n));
assert(equal b (slice (append a b) n (n + m)));
from_vec_propriety #(n + m) (append a b) n
let slice_left_lemma #n a s =
from_vec_propriety #n a s;
division_addition_lemma (from_vec #(n - s) (slice a s n)) (pow2 (n - s)) (from_vec #s (slice a 0 s));
small_division_lemma_1 (from_vec #(n - s) (slice a s n)) (pow2 (n - s))
let slice_right_lemma #n a s =
from_vec_propriety #n a (n - s);
modulo_addition_lemma (from_vec #s (slice a (n - s) n)) (pow2 s) (from_vec #(n - s) (slice a 0 (n - s)));
small_modulo_lemma_1 (from_vec #s (slice a (n - s) n)) (pow2 s)
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let rec ones_to_vec_lemma #n i =
if i = n - 1 then () else ones_to_vec_lemma #(n - 1) i
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let pow2_nth_lemma #n p i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c = nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a = nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a = nth_lemma #n (logand #n a (ones n)) a
let rec subset_vec_le_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_subset_vec #n a b 0 (n-1);
subset_vec_le_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logand_le #n a b =
let va = to_vec a in
let vb = to_vec b in
let vand = to_vec (logand a b) in
subset_vec_le_lemma #n vand va;
subset_vec_le_lemma #n vand vb
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let xor_lemma _ _ = ()
let logxor_inv #n a b =
let open FStar.BitVector in
let open FStar.Seq in
let va = to_vec a in
let vb = to_vec b in
cut(forall (i:nat). i < n ==> index (logxor_vec #n va vb) i = (index va i <> index vb i));
cut (forall (i:nat). {:pattern (index (logxor_vec (logxor_vec va vb) vb) i)}
i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = (xor (xor (index va i)
(index vb i))
(index vb i)));
cut (forall (i:nat). i < n ==> index (logxor_vec (logxor_vec va vb) vb) i = index va i);
Seq.lemma_eq_intro (logxor_vec (logxor_vec va vb) vb) va;
inverse_num_lemma a; inverse_num_lemma b
let logxor_neq_nonzero #n a b =
let va = to_vec a in
let vb = to_vec b in
if logxor a b = 0 then
begin
let open FStar.Seq in
let f (i:nat{i < n}) : Lemma (not (nth #n 0 i)) = zero_nth_lemma #n i in
Classical.forall_intro f;
assert (forall (i:nat{i < n}). index va i = index vb i);
lemma_eq_intro va vb;
assert (from_vec va = from_vec vb)
end
let logor_commutative #n a b = nth_lemma #n (logor #n a b) (logor #n b a)
let logor_associative #n a b c = nth_lemma #n (logor #n (logor #n a b) c) (logor #n a (logor #n b c))
let logor_self #n a = nth_lemma #n (logor #n a a) a
let logor_lemma_1 #n a = nth_lemma (logor #n a (zero n)) a
let logor_lemma_2 #n a = nth_lemma (logor #n a (ones n)) (ones n)
let rec superset_vec_ge_lemma #n a b = match n with
| 1 -> ()
| _ -> lemma_slice_superset_vec #n a b 0 (n-1);
superset_vec_ge_lemma #(n-1) (slice a 0 (n-1)) (slice b 0 (n-1))
let logor_ge #n a b =
let va = to_vec a in
let vb = to_vec b in
let vor = to_vec (logor a b) in
superset_vec_ge_lemma #n vor va;
superset_vec_ge_lemma #n vor vb
let lognot_self #n a = nth_lemma (lognot #n (lognot #n a)) a
let lognot_lemma_1 #n = nth_lemma (lognot #n (zero n)) (ones n)
val to_vec_mod_pow2: #n:nat -> a:uint_t n -> m:pos -> i:nat{n - m <= i /\ i < n} ->
Lemma (requires (a % pow2 m == 0))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_mod_pow2 #n a m i =
if i = n - 1 then
begin
lemma_index_app2 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
mod_mult_exact a 2 (pow2 (m - 1))
end
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
mod_pow2_div2 a m;
to_vec_mod_pow2 #(n - 1) (a / 2) (m - 1) i
end
val to_vec_lt_pow2: #n:nat -> a:uint_t n -> m:nat -> i:nat{i < n - m} ->
Lemma (requires (a < pow2 m))
(ensures (index (to_vec a) i == false))
[SMTPat (index (to_vec #n a) i); SMTPat (pow2 m)]
let rec to_vec_lt_pow2 #n a m i =
if n = 0 then ()
else
if m = 0 then
assert (a == zero n)
else
begin
lemma_index_app1 (to_vec #(n - 1) (a / 2)) (Seq.create 1 (a % 2 = 1)) i;
assert (index (to_vec a) i == index (to_vec #(n - 1) (a / 2)) i);
to_vec_lt_pow2 #(n - 1) (a / 2) (m - 1) i
end
(** Used in the next two lemmas *)
#push-options "--initial_fuel 0 --max_fuel 1 --z3rlimit 40"
let rec index_to_vec_ones #n m i =
let a = pow2 m - 1 in
pow2_le_compat n m;
if m = 0 then one_to_vec_lemma #n i
else if m = n then ones_to_vec_lemma #n i
else if i = n - 1 then ()
else index_to_vec_ones #(n - 1) (m - 1) i
#pop-options
let logor_disjoint #n a b m =
assert (a % pow2 m == 0); // To trigger pattern above
assert (forall (i:nat{n - m <= i /\ i < n}).{:pattern (index (to_vec a) i)}
index (to_vec a) i == false);
assert (b < pow2 m); // To trigger pattern above
assert (forall (i:nat{i < n - m}).{:pattern (index (to_vec b) i)}
index (to_vec b) i == false);
Seq.lemma_split (logor_vec (to_vec a) (to_vec b)) (n - m);
Seq.lemma_eq_intro
(logor_vec (to_vec a) (to_vec b))
(append (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n));
append_lemma #(n - m) #m (slice (to_vec a) 0 (n - m)) (slice (to_vec b) (n - m) n);
slice_left_lemma #n (to_vec a) (n - m);
div_exact_r a (pow2 m);
assert (from_vec #(n - m) (slice (to_vec a) 0 (n - m)) * pow2 m == a);
slice_right_lemma #n (to_vec b) m;
small_modulo_lemma_1 b (pow2 m);
assert (from_vec #m (slice (to_vec b) (n - m) n) == b)
let logand_mask #n a m =
pow2_lt_compat n m;
Seq.lemma_split (logand_vec (to_vec a) (to_vec (pow2 m - 1))) (n - m);
Seq.lemma_eq_intro
(logand_vec (to_vec a) (to_vec (pow2 m - 1)))
(append (zero_vec #(n - m)) (slice (to_vec a) (n - m) n));
append_lemma #(n - m) #m (zero_vec #(n - m)) (slice (to_vec a) (n - m) n);
assert (0 * pow2 m + a % pow2 m == a % pow2 m);
assert (from_vec #(n - m) (zero_vec #(n - m)) == 0);
slice_right_lemma #n (to_vec a) m;
assert (from_vec #m (slice (to_vec a) (n - m) n) == a % pow2 m)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = ()
let shift_right_lemma_1 #n a s i = ()
let shift_right_lemma_2 #n a s i = ()
let shift_left_logand_lemma #n a b s = nth_lemma (shift_left #n (logand #n a b) s) (logand #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logand_lemma #n a b s = nth_lemma (shift_right #n (logand #n a b) s) (logand #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logxor_lemma #n a b s = nth_lemma (shift_left #n (logxor #n a b) s) (logxor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logxor_lemma #n a b s = nth_lemma (shift_right #n (logxor #n a b) s) (logxor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_logor_lemma #n a b s = nth_lemma (shift_left #n (logor #n a b) s) (logor #n (shift_left #n a s) (shift_left #n b s))
let shift_right_logor_lemma #n a b s = nth_lemma (shift_right #n (logor #n a b) s) (logor #n (shift_right #n a s) (shift_right #n b s))
let shift_left_value_aux_1 #n a s = pow2_multiplication_modulo_lemma_1 a n s
let shift_left_value_aux_2 #n a =
assert_norm(a * pow2 0 = a);
small_modulo_lemma_1 a (pow2 n)
let shift_left_value_aux_3 #n a s =
append_lemma #(n - s) #s (slice (to_vec a) s n) (zero_vec #s);
slice_right_lemma #n (to_vec a) (n - s);
pow2_multiplication_modulo_lemma_2 a n s
let shift_left_value_lemma #n a s =
if s >= n then shift_left_value_aux_1 #n a s
else if s = 0 then shift_left_value_aux_2 #n a
else shift_left_value_aux_3 #n a s
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
small_division_lemma_1 a (pow2 s)
let shift_right_value_aux_2 #n a = assert_norm (pow2 0 == 1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt.uint_t n -> s: Prims.pos{s < n}
-> FStar.Pervasives.Lemma (ensures FStar.UInt.shift_right a s = a / Prims.pow2 s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt.slice_left_lemma",
"FStar.UInt.to_vec",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.UInt.append_lemma",
"FStar.BitVector.zero_vec",
"FStar.Seq.Base.slice",
"Prims.bool"
] | [] | true | false | true | false | false | let shift_right_value_aux_3 #n a s =
| append_lemma #s #(n - s) (zero_vec #s) (slice (to_vec a) 0 (n - s));
slice_left_lemma #n (to_vec a) (n - s) | false |
Pulse.Checker.VPropEquiv.fst | Pulse.Checker.VPropEquiv.ve_unit_r | val ve_unit_r (g:env) (p:term) : vprop_equiv g (tm_star p tm_emp) p | val ve_unit_r (g:env) (p:term) : vprop_equiv g (tm_star p tm_emp) p | let ve_unit_r g (p:term) : vprop_equiv g (tm_star p tm_emp) p =
VE_Trans _ _ _ _ (VE_Comm _ _ _) (VE_Unit _ _) | {
"file_name": "lib/steel/pulse/Pulse.Checker.VPropEquiv.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 23,
"start_col": 0,
"start_line": 22
} | (*
Copyright 2023 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 Pulse.Checker.VPropEquiv
open Pulse.Syntax
open Pulse.Typing
open FStar.List.Tot | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.VPropEquiv.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | g: Pulse.Typing.Env.env -> p: Pulse.Syntax.Base.term
-> Pulse.Typing.vprop_equiv g (Pulse.Syntax.Base.tm_star p Pulse.Syntax.Base.tm_emp) p | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Typing.VE_Trans",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_emp",
"Pulse.Typing.VE_Comm",
"Pulse.Typing.VE_Unit",
"Pulse.Typing.vprop_equiv"
] | [] | false | false | false | false | false | let ve_unit_r g (p: term) : vprop_equiv g (tm_star p tm_emp) p =
| VE_Trans _ _ _ _ (VE_Comm _ _ _) (VE_Unit _ _) | false |
Pulse.Checker.VPropEquiv.fst | Pulse.Checker.VPropEquiv.list_as_vprop_comm | val list_as_vprop_comm (g:env) (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(list_as_vprop (vp1 @ vp0))) | val list_as_vprop_comm (g:env) (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(list_as_vprop (vp1 @ vp0))) | let list_as_vprop_comm g (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(list_as_vprop (vp1 @ vp0)))
= let d1 : _ = list_as_vprop_append g vp0 vp1 in
let d2 : _ = VE_Sym _ _ _ (list_as_vprop_append g vp1 vp0) in
let d1 : _ = VE_Trans _ _ _ _ d1 (VE_Comm _ _ _) in
VE_Trans _ _ _ _ d1 d2 | {
"file_name": "lib/steel/pulse/Pulse.Checker.VPropEquiv.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 26,
"end_line": 63,
"start_col": 0,
"start_line": 57
} | (*
Copyright 2023 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 Pulse.Checker.VPropEquiv
open Pulse.Syntax
open Pulse.Typing
open FStar.List.Tot
let ve_unit_r g (p:term) : vprop_equiv g (tm_star p tm_emp) p =
VE_Trans _ _ _ _ (VE_Comm _ _ _) (VE_Unit _ _)
let rec list_as_vprop_append g (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star (list_as_vprop vp0)
(list_as_vprop vp1)))
(decreases vp0)
= match vp0 with
| [] ->
let v : vprop_equiv g (list_as_vprop vp1)
(tm_star tm_emp (list_as_vprop vp1)) = VE_Sym _ _ _ (VE_Unit _ _)
in
v
| [hd] ->
(* Need to check vp1 too in this case *)
begin match vp1 with
| [] ->
VE_Sym _ _ _
(VE_Trans _ _ _ _ (VE_Comm g hd tm_emp) (VE_Unit _ hd))
| _::_ ->
VE_Refl _ _
end
| hd::tl ->
let tl_vp1 = list_as_vprop_append g tl vp1 in
let d : vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star hd (tm_star (list_as_vprop tl) (list_as_vprop vp1)))
= VE_Ctxt _ _ _ _ _ (VE_Refl _ hd) tl_vp1
in
let d : vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star (tm_star hd (list_as_vprop tl)) (list_as_vprop vp1))
= VE_Trans _ _ _ _ d (VE_Assoc _ _ _ _) in
d | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.VPropEquiv.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
g: Pulse.Typing.Env.env ->
vp0: Prims.list Pulse.Syntax.Base.term ->
vp1: Prims.list Pulse.Syntax.Base.term
-> Prims.GTot
(Pulse.Typing.vprop_equiv g
(Pulse.Typing.Combinators.list_as_vprop (vp0 @ vp1))
(Pulse.Typing.Combinators.list_as_vprop (vp1 @ vp0))) | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Syntax.Base.term",
"Pulse.Typing.VE_Trans",
"Pulse.Typing.Combinators.list_as_vprop",
"FStar.List.Tot.Base.op_At",
"Pulse.Syntax.Base.tm_star",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.VE_Comm",
"Pulse.Typing.VE_Sym",
"Pulse.Checker.VPropEquiv.list_as_vprop_append"
] | [] | false | false | false | false | false | let list_as_vprop_comm g (vp0: list term) (vp1: list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1)) (list_as_vprop (vp1 @ vp0))) =
| let d1:_ = list_as_vprop_append g vp0 vp1 in
let d2:_ = VE_Sym _ _ _ (list_as_vprop_append g vp1 vp0) in
let d1:_ = VE_Trans _ _ _ _ d1 (VE_Comm _ _ _) in
VE_Trans _ _ _ _ d1 d2 | false |
Pulse.Checker.VPropEquiv.fst | Pulse.Checker.VPropEquiv.list_as_vprop_ctx | val list_as_vprop_ctx (g:env) (vp0 vp0' vp1 vp1':list term)
(_:vprop_equiv g (list_as_vprop vp0) (list_as_vprop vp0'))
(_:vprop_equiv g (list_as_vprop vp1) (list_as_vprop vp1'))
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1)) (list_as_vprop (vp0' @ vp1'))) | val list_as_vprop_ctx (g:env) (vp0 vp0' vp1 vp1':list term)
(_:vprop_equiv g (list_as_vprop vp0) (list_as_vprop vp0'))
(_:vprop_equiv g (list_as_vprop vp1) (list_as_vprop vp1'))
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1)) (list_as_vprop (vp0' @ vp1'))) | let list_as_vprop_ctx g (vp0 vp0' vp1 vp1':list term)
(d0:vprop_equiv g (list_as_vprop vp0) (list_as_vprop vp0'))
(d1:vprop_equiv g (list_as_vprop vp1) (list_as_vprop vp1'))
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1)) (list_as_vprop (vp0' @ vp1')))
= let split_app = list_as_vprop_append _ vp0 vp1 in
let split_app' = list_as_vprop_append _ vp0' vp1' in
let ctxt = VE_Ctxt _ _ _ _ _ d0 d1 in
VE_Trans _ _ _ _ split_app (VE_Trans _ _ _ _ ctxt (VE_Sym _ _ _ split_app')) | {
"file_name": "lib/steel/pulse/Pulse.Checker.VPropEquiv.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 80,
"end_line": 79,
"start_col": 0,
"start_line": 71
} | (*
Copyright 2023 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 Pulse.Checker.VPropEquiv
open Pulse.Syntax
open Pulse.Typing
open FStar.List.Tot
let ve_unit_r g (p:term) : vprop_equiv g (tm_star p tm_emp) p =
VE_Trans _ _ _ _ (VE_Comm _ _ _) (VE_Unit _ _)
let rec list_as_vprop_append g (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star (list_as_vprop vp0)
(list_as_vprop vp1)))
(decreases vp0)
= match vp0 with
| [] ->
let v : vprop_equiv g (list_as_vprop vp1)
(tm_star tm_emp (list_as_vprop vp1)) = VE_Sym _ _ _ (VE_Unit _ _)
in
v
| [hd] ->
(* Need to check vp1 too in this case *)
begin match vp1 with
| [] ->
VE_Sym _ _ _
(VE_Trans _ _ _ _ (VE_Comm g hd tm_emp) (VE_Unit _ hd))
| _::_ ->
VE_Refl _ _
end
| hd::tl ->
let tl_vp1 = list_as_vprop_append g tl vp1 in
let d : vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star hd (tm_star (list_as_vprop tl) (list_as_vprop vp1)))
= VE_Ctxt _ _ _ _ _ (VE_Refl _ hd) tl_vp1
in
let d : vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star (tm_star hd (list_as_vprop tl)) (list_as_vprop vp1))
= VE_Trans _ _ _ _ d (VE_Assoc _ _ _ _) in
d
let list_as_vprop_comm g (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(list_as_vprop (vp1 @ vp0)))
= let d1 : _ = list_as_vprop_append g vp0 vp1 in
let d2 : _ = VE_Sym _ _ _ (list_as_vprop_append g vp1 vp0) in
let d1 : _ = VE_Trans _ _ _ _ d1 (VE_Comm _ _ _) in
VE_Trans _ _ _ _ d1 d2
let list_as_vprop_assoc g (vp0 vp1 vp2:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ (vp1 @ vp2)))
(list_as_vprop ((vp0 @ vp1) @ vp2)))
= List.Tot.append_assoc vp0 vp1 vp2;
VE_Refl _ _ | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.VPropEquiv.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
g: Pulse.Typing.Env.env ->
vp0: Prims.list Pulse.Syntax.Base.term ->
vp0': Prims.list Pulse.Syntax.Base.term ->
vp1: Prims.list Pulse.Syntax.Base.term ->
vp1': Prims.list Pulse.Syntax.Base.term ->
d0:
Pulse.Typing.vprop_equiv g
(Pulse.Typing.Combinators.list_as_vprop vp0)
(Pulse.Typing.Combinators.list_as_vprop vp0') ->
d1:
Pulse.Typing.vprop_equiv g
(Pulse.Typing.Combinators.list_as_vprop vp1)
(Pulse.Typing.Combinators.list_as_vprop vp1')
-> Prims.GTot
(Pulse.Typing.vprop_equiv g
(Pulse.Typing.Combinators.list_as_vprop (vp0 @ vp1))
(Pulse.Typing.Combinators.list_as_vprop (vp0' @ vp1'))) | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Syntax.Base.term",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.Combinators.list_as_vprop",
"Pulse.Typing.VE_Trans",
"FStar.List.Tot.Base.op_At",
"Pulse.Syntax.Base.tm_star",
"Pulse.Typing.VE_Sym",
"Pulse.Typing.VE_Ctxt",
"Pulse.Checker.VPropEquiv.list_as_vprop_append"
] | [] | false | false | false | false | false | let list_as_vprop_ctx
g
(vp0: list term)
(vp0': list term)
(vp1: list term)
(vp1': list term)
(d0: vprop_equiv g (list_as_vprop vp0) (list_as_vprop vp0'))
(d1: vprop_equiv g (list_as_vprop vp1) (list_as_vprop vp1'))
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1)) (list_as_vprop (vp0' @ vp1'))) =
| let split_app = list_as_vprop_append _ vp0 vp1 in
let split_app' = list_as_vprop_append _ vp0' vp1' in
let ctxt = VE_Ctxt _ _ _ _ _ d0 d1 in
VE_Trans _ _ _ _ split_app (VE_Trans _ _ _ _ ctxt (VE_Sym _ _ _ split_app')) | false |
Pulse.Checker.VPropEquiv.fst | Pulse.Checker.VPropEquiv.list_as_vprop_singleton | val list_as_vprop_singleton (g:env) (p q:term) (d:vprop_equiv g p q)
: GTot (vprop_equiv g (list_as_vprop [p]) (list_as_vprop [q])) | val list_as_vprop_singleton (g:env) (p q:term) (d:vprop_equiv g p q)
: GTot (vprop_equiv g (list_as_vprop [p]) (list_as_vprop [q])) | let list_as_vprop_singleton g
(p q:term)
(d:vprop_equiv g p q)
: GTot (vprop_equiv g (list_as_vprop [p]) (list_as_vprop [q]))
= d | {
"file_name": "lib/steel/pulse/Pulse.Checker.VPropEquiv.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 85,
"start_col": 0,
"start_line": 81
} | (*
Copyright 2023 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 Pulse.Checker.VPropEquiv
open Pulse.Syntax
open Pulse.Typing
open FStar.List.Tot
let ve_unit_r g (p:term) : vprop_equiv g (tm_star p tm_emp) p =
VE_Trans _ _ _ _ (VE_Comm _ _ _) (VE_Unit _ _)
let rec list_as_vprop_append g (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star (list_as_vprop vp0)
(list_as_vprop vp1)))
(decreases vp0)
= match vp0 with
| [] ->
let v : vprop_equiv g (list_as_vprop vp1)
(tm_star tm_emp (list_as_vprop vp1)) = VE_Sym _ _ _ (VE_Unit _ _)
in
v
| [hd] ->
(* Need to check vp1 too in this case *)
begin match vp1 with
| [] ->
VE_Sym _ _ _
(VE_Trans _ _ _ _ (VE_Comm g hd tm_emp) (VE_Unit _ hd))
| _::_ ->
VE_Refl _ _
end
| hd::tl ->
let tl_vp1 = list_as_vprop_append g tl vp1 in
let d : vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star hd (tm_star (list_as_vprop tl) (list_as_vprop vp1)))
= VE_Ctxt _ _ _ _ _ (VE_Refl _ hd) tl_vp1
in
let d : vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star (tm_star hd (list_as_vprop tl)) (list_as_vprop vp1))
= VE_Trans _ _ _ _ d (VE_Assoc _ _ _ _) in
d
let list_as_vprop_comm g (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(list_as_vprop (vp1 @ vp0)))
= let d1 : _ = list_as_vprop_append g vp0 vp1 in
let d2 : _ = VE_Sym _ _ _ (list_as_vprop_append g vp1 vp0) in
let d1 : _ = VE_Trans _ _ _ _ d1 (VE_Comm _ _ _) in
VE_Trans _ _ _ _ d1 d2
let list_as_vprop_assoc g (vp0 vp1 vp2:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ (vp1 @ vp2)))
(list_as_vprop ((vp0 @ vp1) @ vp2)))
= List.Tot.append_assoc vp0 vp1 vp2;
VE_Refl _ _
let list_as_vprop_ctx g (vp0 vp0' vp1 vp1':list term)
(d0:vprop_equiv g (list_as_vprop vp0) (list_as_vprop vp0'))
(d1:vprop_equiv g (list_as_vprop vp1) (list_as_vprop vp1'))
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1)) (list_as_vprop (vp0' @ vp1')))
= let split_app = list_as_vprop_append _ vp0 vp1 in
let split_app' = list_as_vprop_append _ vp0' vp1' in
let ctxt = VE_Ctxt _ _ _ _ _ d0 d1 in
VE_Trans _ _ _ _ split_app (VE_Trans _ _ _ _ ctxt (VE_Sym _ _ _ split_app')) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.VPropEquiv.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
g: Pulse.Typing.Env.env ->
p: Pulse.Syntax.Base.term ->
q: Pulse.Syntax.Base.term ->
d: Pulse.Typing.vprop_equiv g p q
-> Prims.GTot
(Pulse.Typing.vprop_equiv g
(Pulse.Typing.Combinators.list_as_vprop [p])
(Pulse.Typing.Combinators.list_as_vprop [q])) | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.Combinators.list_as_vprop",
"Prims.Cons",
"Prims.Nil"
] | [] | false | false | false | false | false | let list_as_vprop_singleton g (p: term) (q: term) (d: vprop_equiv g p q)
: GTot (vprop_equiv g (list_as_vprop [p]) (list_as_vprop [q])) =
| d | false |
Pulse.Checker.VPropEquiv.fst | Pulse.Checker.VPropEquiv.vprop_equiv_swap_equiv | val vprop_equiv_swap_equiv (g:_) (l0 l2:list term)
(p q:term) (d_p_q:vprop_equiv g p q)
: GTot (vprop_equiv g (list_as_vprop ((l0 @ [q]) @ l2))
(list_as_vprop ([p] @ (l0 @ l2)))) | val vprop_equiv_swap_equiv (g:_) (l0 l2:list term)
(p q:term) (d_p_q:vprop_equiv g p q)
: GTot (vprop_equiv g (list_as_vprop ((l0 @ [q]) @ l2))
(list_as_vprop ([p] @ (l0 @ l2)))) | let vprop_equiv_swap_equiv (g:_)
(l0 l2:list term)
(p q:term) (d_p_q:vprop_equiv g p q)
: vprop_equiv g (list_as_vprop ((l0 @ [q]) @ l2))
(list_as_vprop ([p] @ (l0 @ l2)))
= let d : vprop_equiv g (list_as_vprop ((l0 @ [q]) @ l2))
(list_as_vprop (([q] @ l0) @ l2))
= list_as_vprop_ctx g (l0 @ [q]) ([q] @ l0) l2 l2
(list_as_vprop_comm g l0 [q])
(VE_Refl _ _) in
let d' : vprop_equiv g (list_as_vprop (([q] @ l0) @ l2))
(list_as_vprop ([q] @ (l0 @ l2)))
= List.Tot.append_assoc [q] l0 l2;
VE_Refl _ _ in
let d : vprop_equiv g (list_as_vprop ((l0 @ [q]) @ l2))
(list_as_vprop ([q] @ (l0 @ l2)))
= VE_Trans _ _ _ _ d d' in
let d_q_p = VE_Sym _ _ _ d_p_q in
let d' : vprop_equiv g (list_as_vprop [q]) (list_as_vprop [p]) = d_q_p in
let d' : vprop_equiv g (list_as_vprop ([q] @ (l0 @ l2)))
(list_as_vprop ([p] @ (l0 @ l2)))
= list_as_vprop_ctx g [q] [p] (l0 @ l2) _ d' (VE_Refl _ _) in
VE_Trans _ _ _ _ d d' | {
"file_name": "lib/steel/pulse/Pulse.Checker.VPropEquiv.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 25,
"end_line": 131,
"start_col": 0,
"start_line": 109
} | (*
Copyright 2023 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 Pulse.Checker.VPropEquiv
open Pulse.Syntax
open Pulse.Typing
open FStar.List.Tot
let ve_unit_r g (p:term) : vprop_equiv g (tm_star p tm_emp) p =
VE_Trans _ _ _ _ (VE_Comm _ _ _) (VE_Unit _ _)
let rec list_as_vprop_append g (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star (list_as_vprop vp0)
(list_as_vprop vp1)))
(decreases vp0)
= match vp0 with
| [] ->
let v : vprop_equiv g (list_as_vprop vp1)
(tm_star tm_emp (list_as_vprop vp1)) = VE_Sym _ _ _ (VE_Unit _ _)
in
v
| [hd] ->
(* Need to check vp1 too in this case *)
begin match vp1 with
| [] ->
VE_Sym _ _ _
(VE_Trans _ _ _ _ (VE_Comm g hd tm_emp) (VE_Unit _ hd))
| _::_ ->
VE_Refl _ _
end
| hd::tl ->
let tl_vp1 = list_as_vprop_append g tl vp1 in
let d : vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star hd (tm_star (list_as_vprop tl) (list_as_vprop vp1)))
= VE_Ctxt _ _ _ _ _ (VE_Refl _ hd) tl_vp1
in
let d : vprop_equiv g (list_as_vprop (vp0 @ vp1))
(tm_star (tm_star hd (list_as_vprop tl)) (list_as_vprop vp1))
= VE_Trans _ _ _ _ d (VE_Assoc _ _ _ _) in
d
let list_as_vprop_comm g (vp0 vp1:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1))
(list_as_vprop (vp1 @ vp0)))
= let d1 : _ = list_as_vprop_append g vp0 vp1 in
let d2 : _ = VE_Sym _ _ _ (list_as_vprop_append g vp1 vp0) in
let d1 : _ = VE_Trans _ _ _ _ d1 (VE_Comm _ _ _) in
VE_Trans _ _ _ _ d1 d2
let list_as_vprop_assoc g (vp0 vp1 vp2:list term)
: GTot (vprop_equiv g (list_as_vprop (vp0 @ (vp1 @ vp2)))
(list_as_vprop ((vp0 @ vp1) @ vp2)))
= List.Tot.append_assoc vp0 vp1 vp2;
VE_Refl _ _
let list_as_vprop_ctx g (vp0 vp0' vp1 vp1':list term)
(d0:vprop_equiv g (list_as_vprop vp0) (list_as_vprop vp0'))
(d1:vprop_equiv g (list_as_vprop vp1) (list_as_vprop vp1'))
: GTot (vprop_equiv g (list_as_vprop (vp0 @ vp1)) (list_as_vprop (vp0' @ vp1')))
= let split_app = list_as_vprop_append _ vp0 vp1 in
let split_app' = list_as_vprop_append _ vp0' vp1' in
let ctxt = VE_Ctxt _ _ _ _ _ d0 d1 in
VE_Trans _ _ _ _ split_app (VE_Trans _ _ _ _ ctxt (VE_Sym _ _ _ split_app'))
let list_as_vprop_singleton g
(p q:term)
(d:vprop_equiv g p q)
: GTot (vprop_equiv g (list_as_vprop [p]) (list_as_vprop [q]))
= d
let rec vprop_list_equiv (g:env)
(vp:term)
: GTot (vprop_equiv g vp (canon_vprop vp))
(decreases vp)
= match vp.t with
| Tm_Emp -> VE_Refl _ _
| Tm_Star vp0 vp1 ->
let eq0 = vprop_list_equiv g vp0 in
let eq1 = vprop_list_equiv g vp1 in
let app_eq
: vprop_equiv _ (canon_vprop vp) (tm_star (canon_vprop vp0) (canon_vprop vp1))
= list_as_vprop_append g (vprop_as_list vp0) (vprop_as_list vp1)
in
let step
: vprop_equiv _ vp (tm_star (canon_vprop vp0) (canon_vprop vp1))
= VE_Ctxt _ _ _ _ _ eq0 eq1
in
VE_Trans _ _ _ _ step (VE_Sym _ _ _ app_eq)
| _ ->
VE_Refl _ _ | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.VPropEquiv.fst"
} | [
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false |
g: Pulse.Typing.Env.env ->
l0: Prims.list Pulse.Syntax.Base.term ->
l2: Prims.list Pulse.Syntax.Base.term ->
p: Pulse.Syntax.Base.term ->
q: Pulse.Syntax.Base.term ->
d_p_q: Pulse.Typing.vprop_equiv g p q
-> Prims.GTot
(Pulse.Typing.vprop_equiv g
(Pulse.Typing.Combinators.list_as_vprop ((l0 @ [q]) @ l2))
(Pulse.Typing.Combinators.list_as_vprop ([p] @ l0 @ l2))) | Prims.GTot | [
"sometrivial"
] | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Syntax.Base.term",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.VE_Trans",
"Pulse.Typing.Combinators.list_as_vprop",
"FStar.List.Tot.Base.op_At",
"Prims.Cons",
"Prims.Nil",
"Pulse.Checker.VPropEquiv.list_as_vprop_ctx",
"Pulse.Typing.VE_Refl",
"Pulse.Typing.VE_Sym",
"Prims.unit",
"FStar.List.Tot.Properties.append_assoc",
"Pulse.Checker.VPropEquiv.list_as_vprop_comm"
] | [] | false | false | false | false | false | let vprop_equiv_swap_equiv (g: _) (l0 l2: list term) (p q: term) (d_p_q: vprop_equiv g p q)
: vprop_equiv g (list_as_vprop ((l0 @ [q]) @ l2)) (list_as_vprop ([p] @ (l0 @ l2))) =
| let d:vprop_equiv g (list_as_vprop ((l0 @ [q]) @ l2)) (list_as_vprop (([q] @ l0) @ l2)) =
list_as_vprop_ctx g (l0 @ [q]) ([q] @ l0) l2 l2 (list_as_vprop_comm g l0 [q]) (VE_Refl _ _)
in
let d':vprop_equiv g (list_as_vprop (([q] @ l0) @ l2)) (list_as_vprop ([q] @ (l0 @ l2))) =
List.Tot.append_assoc [q] l0 l2;
VE_Refl _ _
in
let d:vprop_equiv g (list_as_vprop ((l0 @ [q]) @ l2)) (list_as_vprop ([q] @ (l0 @ l2))) =
VE_Trans _ _ _ _ d d'
in
let d_q_p = VE_Sym _ _ _ d_p_q in
let d':vprop_equiv g (list_as_vprop [q]) (list_as_vprop [p]) = d_q_p in
let d':vprop_equiv g (list_as_vprop ([q] @ (l0 @ l2))) (list_as_vprop ([p] @ (l0 @ l2))) =
list_as_vprop_ctx g [q] [p] (l0 @ l2) _ d' (VE_Refl _ _)
in
VE_Trans _ _ _ _ d d' | false |
LowParseWriters.NoHoare.fst | LowParseWriters.NoHoare.read_reify_trivial | val read_reify_trivial
(#a: Type)
(#l: memory_invariant)
(f: (unit -> ERead a True (fun _ -> True) (fun _ -> True) l))
: Tot (read_repr a l) | val read_reify_trivial
(#a: Type)
(#l: memory_invariant)
(f: (unit -> ERead a True (fun _ -> True) (fun _ -> True) l))
: Tot (read_repr a l) | let read_reify_trivial
(#a: Type)
(#l: memory_invariant)
(f: (unit -> ERead a True (fun _ -> True) (fun _ -> True) l))
: Tot (read_repr a l)
= reify (f ()) | {
"file_name": "examples/layeredeffects/LowParseWriters.NoHoare.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 14,
"end_line": 17,
"start_col": 0,
"start_line": 12
} | module LowParseWriters.NoHoare
include LowParseWriters
inline_for_extraction
let read_repr
(t: Type)
(inv: memory_invariant)
: Tot Type
= read_repr t True (fun _ -> True) (fun _ -> True) inv | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParseWriters.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowParseWriters.NoHoare.fst"
} | [
{
"abbrev": false,
"full_module": "LowParseWriters",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParseWriters",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParseWriters",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"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"
} | false | f: (_: Prims.unit -> LowParseWriters.ERead a) -> LowParseWriters.NoHoare.read_repr a l | Prims.Tot | [
"total"
] | [] | [
"LowParseWriters.memory_invariant",
"Prims.unit",
"Prims.l_True",
"LowParseWriters.NoHoare.read_repr"
] | [] | false | false | false | false | false | let read_reify_trivial
(#a: Type)
(#l: memory_invariant)
(f: (unit -> ERead a True (fun _ -> True) (fun _ -> True) l))
: Tot (read_repr a l) =
| reify (f ()) | false |
Hacl.Impl.HSalsa20.fst | Hacl.Impl.HSalsa20.hsalsa20 | val hsalsa20:
out:lbuffer uint8 32ul
-> key:lbuffer uint8 32ul
-> n:lbuffer uint8 16ul ->
Stack unit
(requires fun h -> live h key /\ live h n /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.hsalsa20 (as_seq h0 key) (as_seq h0 n)) | val hsalsa20:
out:lbuffer uint8 32ul
-> key:lbuffer uint8 32ul
-> n:lbuffer uint8 16ul ->
Stack unit
(requires fun h -> live h key /\ live h n /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.hsalsa20 (as_seq h0 key) (as_seq h0 n)) | let hsalsa20 out key n =
push_frame();
let ctx = create 16ul (u32 0) in
hsalsa20_init ctx key n;
Salsa20.rounds ctx;
let r0 = ctx.(0ul) in
let r1 = ctx.(5ul) in
let r2 = ctx.(10ul) in
let r3 = ctx.(15ul) in
let r4 = ctx.(6ul) in
let r5 = ctx.(7ul) in
let r6 = ctx.(8ul) in
let r7 = ctx.(9ul) in
[@inline_let]
let res_l = [r0;r1;r2;r3;r4;r5;r6;r7] in
assert_norm (List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le #U32 8ul out res;
pop_frame() | {
"file_name": "code/salsa20/Hacl.Impl.HSalsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 86,
"start_col": 0,
"start_line": 68
} | module Hacl.Impl.HSalsa20
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Salsa20.Core32
module ST = FStar.HyperStack.ST
module Spec = Spec.Salsa20
module Loop = Lib.LoopCombinators
module Salsa20 = Hacl.Impl.Salsa20
#set-options "--z3rlimit 100 --max_fuel 1 --max_ifuel 1"
inline_for_extraction
val hsalsa20_init:
ctx:state
-> k:lbuffer uint8 32ul
-> n:lbuffer uint8 16ul ->
Stack unit
(requires fun h ->
live h ctx /\ live h k /\ live h n /\
disjoint ctx k /\ disjoint ctx n /\
as_seq h ctx == Lib.Sequence.create 16 (u32 0))
(ensures fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\
as_seq h1 ctx == Spec.hsalsa20_init (as_seq h0 k) (as_seq h0 n))
let hsalsa20_init ctx k n =
let h0 = ST.get() in
push_frame();
let k32 = create 8ul (u32 0) in
let n32 = create 4ul (u32 0) in
let h0' = ST.get() in
uints_from_bytes_le k32 k;
uints_from_bytes_le n32 n;
let k0 = sub k32 0ul 4ul in
let k1 = sub k32 4ul 4ul in
ctx.(0ul) <- Spec.constant0;
update_sub #MUT ctx 1ul 4ul k0;
ctx.(5ul) <- Spec.constant1;
update_sub #MUT ctx 6ul 4ul n32;
ctx.(10ul) <- Spec.constant2;
update_sub #MUT ctx 11ul 4ul k1;
ctx.(15ul) <- Spec.constant3;
let h1' = ST.get() in
assert (modifies (loc ctx |+| loc k32 |+| loc n32) h0' h1');
pop_frame();
let h1 = ST.get() in
assert (modifies (loc ctx) h0 h1)
val hsalsa20:
out:lbuffer uint8 32ul
-> key:lbuffer uint8 32ul
-> n:lbuffer uint8 16ul ->
Stack unit
(requires fun h -> live h key /\ live h n /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.hsalsa20 (as_seq h0 key) (as_seq h0 n)) | {
"checked_file": "/",
"dependencies": [
"Spec.Salsa20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Salsa20.Core32.fst.checked",
"Hacl.Impl.Salsa20.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.HSalsa20.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Salsa20",
"short_module": "Salsa20"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Spec.Salsa20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Salsa20.Core32",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"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": 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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 16ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.ByteBuffer.uints_to_bytes_le",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.PUB",
"FStar.Pervasives.normalize_term",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.List.Tot.Base.length",
"Lib.Buffer.createL",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.size",
"Lib.IntTypes.size_nat",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Lib.Buffer.op_Array_Access",
"Lib.IntTypes.uint32",
"Hacl.Impl.Salsa20.rounds",
"Hacl.Impl.HSalsa20.hsalsa20_init",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.u32",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let hsalsa20 out key n =
| push_frame ();
let ctx = create 16ul (u32 0) in
hsalsa20_init ctx key n;
Salsa20.rounds ctx;
let r0 = ctx.(0ul) in
let r1 = ctx.(5ul) in
let r2 = ctx.(10ul) in
let r3 = ctx.(15ul) in
let r4 = ctx.(6ul) in
let r5 = ctx.(7ul) in
let r6 = ctx.(8ul) in
let r7 = ctx.(9ul) in
[@@ inline_let ]let res_l = [r0; r1; r2; r3; r4; r5; r6; r7] in
assert_norm (List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le #U32 8ul out res;
pop_frame () | false |
Spec.Box.Test.fst | Spec.Box.Test.nonce | val nonce:lbytes 24 | val nonce:lbytes 24 | let nonce : lbytes 24 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x01uy; 0x02uy; 0x03uy; 0x04uy; 0x05uy; 0x06uy; 0x07uy;
0x08uy; 0x09uy; 0x10uy; 0x11uy; 0x12uy; 0x13uy; 0x14uy; 0x15uy;
0x16uy; 0x17uy; 0x18uy; 0x19uy; 0x20uy; 0x21uy; 0x22uy; 0x23uy
] in
assert_norm (List.Tot.length l == 24);
of_list l | {
"file_name": "specs/tests/Spec.Box.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 36,
"start_col": 0,
"start_line": 29
} | module Spec.Box.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Box
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let plain : lbytes 72 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x01uy; 0x02uy; 0x03uy; 0x04uy; 0x05uy; 0x06uy; 0x07uy;
0x08uy; 0x09uy; 0x10uy; 0x11uy; 0x12uy; 0x13uy; 0x14uy; 0x15uy;
0x16uy; 0x17uy; 0x18uy; 0x19uy; 0x20uy; 0x21uy; 0x22uy; 0x23uy;
0x00uy; 0x01uy; 0x02uy; 0x03uy; 0x04uy; 0x05uy; 0x06uy; 0x07uy;
0x08uy; 0x09uy; 0x10uy; 0x11uy; 0x12uy; 0x13uy; 0x14uy; 0x15uy;
0x16uy; 0x17uy; 0x18uy; 0x19uy; 0x20uy; 0x21uy; 0x22uy; 0x23uy;
0x00uy; 0x01uy; 0x02uy; 0x03uy; 0x04uy; 0x05uy; 0x06uy; 0x07uy;
0x08uy; 0x09uy; 0x10uy; 0x11uy; 0x12uy; 0x13uy; 0x14uy; 0x15uy;
0x16uy; 0x17uy; 0x18uy; 0x19uy; 0x20uy; 0x21uy; 0x22uy; 0x23uy
] in
assert_norm (List.Tot.length l == 72);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"Spec.Box.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Box.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Box",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Box",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Box",
"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
}
] | {
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 24 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let nonce:lbytes 24 =
| let l =
List.Tot.map u8_from_UInt8
[
0x00uy; 0x01uy; 0x02uy; 0x03uy; 0x04uy; 0x05uy; 0x06uy; 0x07uy; 0x08uy; 0x09uy; 0x10uy; 0x11uy;
0x12uy; 0x13uy; 0x14uy; 0x15uy; 0x16uy; 0x17uy; 0x18uy; 0x19uy; 0x20uy; 0x21uy; 0x22uy; 0x23uy
]
in
assert_norm (List.Tot.length l == 24);
of_list l | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.