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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Lib.IntTypes.fst | Lib.IntTypes.mod | val mod: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> int_t t PUB | val mod: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> int_t t PUB | let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 1057,
"start_col": 0,
"start_line": 1047
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Lib.IntTypes.int_t t Lib.IntTypes.PUB ->
b:
Lib.IntTypes.int_t t Lib.IntTypes.PUB
{ Lib.IntTypes.v b <> 0 /\
(Lib.IntTypes.unsigned t \/ Lib.IntTypes.range (Lib.IntTypes.v a / Lib.IntTypes.v b) t) }
-> Lib.IntTypes.int_t t Lib.IntTypes.PUB | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_U128",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.op_disEquality",
"Prims.int",
"Lib.IntTypes.v",
"Prims.l_or",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.range",
"FStar.Int.op_Slash",
"FStar.UInt8.rem",
"FStar.UInt16.rem",
"FStar.UInt32.rem",
"FStar.UInt64.rem",
"FStar.Int8.rem",
"Prims.unit",
"FStar.Int.pow2_values",
"FStar.Int16.rem",
"FStar.Int32.rem",
"FStar.Int64.rem"
] | [] | false | false | false | false | false | let mod #t x y =
| match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 ->
Int.pow2_values 8;
Int8.rem x y
| S16 ->
Int.pow2_values 16;
Int16.rem x y
| S32 ->
Int.pow2_values 32;
Int32.rem x y
| S64 ->
Int.pow2_values 64;
Int64.rem x y | false |
Lib.IntTypes.fst | Lib.IntTypes.mod_lemma | val mod_lemma: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> Lemma (if signed t then
v (mod a b) == FStar.Int.mod #(bits t) (v a) (v b)
else
v (mod a b) == FStar.UInt.mod #(bits t) (v a) (v b))
[SMTPat (v #t (mod #t a b))] | val mod_lemma: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> Lemma (if signed t then
v (mod a b) == FStar.Int.mod #(bits t) (v a) (v b)
else
v (mod a b) == FStar.UInt.mod #(bits t) (v a) (v b))
[SMTPat (v #t (mod #t a b))] | let mod_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 1065,
"start_col": 0,
"start_line": 1059
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Lib.IntTypes.int_t t Lib.IntTypes.PUB ->
b:
Lib.IntTypes.int_t t Lib.IntTypes.PUB
{ Lib.IntTypes.v b <> 0 /\
(Lib.IntTypes.unsigned t \/ Lib.IntTypes.range (Lib.IntTypes.v a / Lib.IntTypes.v b) t) }
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.signed t with
| true ->
Lib.IntTypes.v (Lib.IntTypes.mod a b) ==
FStar.Int.mod (Lib.IntTypes.v a) (Lib.IntTypes.v b)
| _ ->
Lib.IntTypes.v (Lib.IntTypes.mod a b) ==
FStar.UInt.mod (Lib.IntTypes.v a) (Lib.IntTypes.v b))
<:
Type0)) [SMTPat (Lib.IntTypes.v (Lib.IntTypes.mod a b))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_U128",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.op_disEquality",
"Prims.int",
"Lib.IntTypes.v",
"Prims.l_or",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.range",
"FStar.Int.op_Slash",
"FStar.Int.pow2_values",
"Prims.unit"
] | [] | false | false | true | false | false | let mod_lemma #t a b =
| match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64 | false |
Main.fst | Main.with_z3_thread_or | val with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit)) | val with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit)) | let with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit))
= if batch
then
let thr = Z3.with_z3_thread debug transcript f in
Some (fun _ ->
Z3.wait_for_z3_thread thr;
build_and_run_test_exe out_dir
)
else begin
Z3.with_z3 debug transcript f;
None
end | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 504,
"start_col": 0,
"start_line": 487
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false)
let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end
let build_and_run_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []
end | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
batch: Prims.bool ->
out_dir: Prims.string ->
debug: Prims.bool ->
transcript: FStar.Pervasives.Native.option Prims.string ->
f: (_: Z3.Base.z3 -> FStar.All.ML Prims.unit)
-> FStar.All.ML (FStar.Pervasives.Native.option (_: Prims.unit -> FStar.All.ML Prims.unit)) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"FStar.Pervasives.Native.option",
"Z3.Base.z3",
"Prims.unit",
"FStar.Pervasives.Native.Some",
"Main.build_and_run_test_exe",
"Z3.wait_for_z3_thread",
"Z3.z3_thread",
"Z3.with_z3_thread",
"FStar.Pervasives.Native.None",
"Z3.with_z3"
] | [] | false | true | false | false | false | let with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit)) =
| if batch
then
let thr = Z3.with_z3_thread debug transcript f in
Some
(fun _ ->
Z3.wait_for_z3_thread thr;
build_and_run_test_exe out_dir)
else
(Z3.with_z3 debug transcript f;
None) | false |
Lib.IntTypes.fst | Lib.IntTypes.lte_mask_lemma | val lte_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a <= v b then v (lte_mask a b) == ones_v t
else v (lte_mask a b) == 0)
[SMTPat (lte_mask #t a b)] | val lte_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a <= v b then v (lte_mask a b) == ones_v t
else v (lte_mask a b) == 0)
[SMTPat (lte_mask #t a b)] | let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 945,
"start_col": 0,
"start_line": 933
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.v a <= Lib.IntTypes.v b with
| true -> Lib.IntTypes.v (Lib.IntTypes.lte_mask a b) == Lib.IntTypes.ones_v t
| _ -> Lib.IntTypes.v (Lib.IntTypes.lte_mask a b) == 0)
<:
Type0)) [SMTPat (Lib.IntTypes.lte_mask a b)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.logor",
"Lib.IntTypes.u1",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"FStar.UInt.logor_lemma_1",
"Lib.IntTypes.bits",
"Lib.IntTypes.lt_mask",
"Prims.bool",
"Prims.op_Equality",
"Lib.IntTypes.range_t",
"FStar.UInt.logor_lemma_2",
"Prims.unit"
] | [] | false | false | true | false | false | let lte_mask_lemma #t a b =
| match t with
| U1 ->
assert_norm (logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8
| U16
| U32
| U64
| U128 ->
if v a > v b
then UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else
if v a = v b
then UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else UInt.logor_lemma_1 #(bits t) (v (lt_mask a b)) | false |
Lib.IntTypes.fst | Lib.IntTypes.mod_mask_lemma | val mod_mask_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l -> m:shiftval t{pow2 (uint_v m) <= maxint t}
-> Lemma (v (a `logand` mod_mask m) == v a % pow2 (v m))
[SMTPat (a `logand` mod_mask #t m)] | val mod_mask_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l -> m:shiftval t{pow2 (uint_v m) <= maxint t}
-> Lemma (v (a `logand` mod_mask m) == v a % pow2 (v m))
[SMTPat (a `logand` mod_mask #t m)] | let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 976,
"start_col": 0,
"start_line": 958
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Lib.IntTypes.int_t t l ->
m: Lib.IntTypes.shiftval t {Prims.pow2 (Lib.IntTypes.uint_v m) <= Lib.IntTypes.maxint t}
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Lib.IntTypes.logand a (Lib.IntTypes.mod_mask m)) ==
Lib.IntTypes.v a % Prims.pow2 (Lib.IntTypes.v m))
[SMTPat (Lib.IntTypes.logand a (Lib.IntTypes.mod_mask m))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.shiftval",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.pow2",
"Lib.IntTypes.uint_v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.maxint",
"Prims.op_BarBar",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.v",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.logand_lemma_1",
"Lib.IntTypes.bits",
"Prims.bool",
"FStar.UInt.logand_mask",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_plus",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.pow2_le_compat",
"FStar.Math.Lemmas.pow2_plus",
"Prims.op_Addition",
"Lib.IntTypes.range",
"Lib.IntTypes.mod_mask_value"
] | [] | false | false | true | false | false | let mod_mask_lemma #t #l a m =
| mod_mask_value #t #l m;
if unsigned t || 0 <= v a
then if v m = 0 then UInt.logand_lemma_1 #(bits t) (v a) else UInt.logand_mask #(bits t) (v a) (v m)
else
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then UInt.logand_lemma_1 #(bits t) a2 else UInt.logand_mask #(bits t) a2 (v m) | false |
Main.fst | Main.produce_z3_and_test | val produce_z3_and_test (batch: bool) (out_dir name: string) : Tot process_files_t | val produce_z3_and_test (batch: bool) (out_dir name: string) : Tot process_files_t | let produce_z3_and_test
(batch: bool)
(out_dir: string)
(name: string)
: Tot process_files_t
= produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_test out_dir out_file z3 prog name nbwitnesses (Options.get_z3_branch_depth ()) (Options.get_z3_pos_test ()) (Options.get_z3_neg_test ())
) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 531,
"start_col": 0,
"start_line": 524
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false)
let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end
let build_and_run_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []
end
let with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit))
= if batch
then
let thr = Z3.with_z3_thread debug transcript f in
Some (fun _ ->
Z3.wait_for_z3_thread thr;
build_and_run_test_exe out_dir
)
else begin
Z3.with_z3 debug transcript f;
None
end
let produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let nbwitnesses = Options.get_z3_witnesses () in
let buf : ref string = alloc "" in
let prog = process_files_for_z3 (fun s -> buf := !buf ^ s) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
with_z3_thread_or batch out_dir (Options.get_debug ()) (Options.get_save_z3_transcript ()) (fun z3 ->
z3.to_z3 !buf;
do_test (if batch then Some (OS.concat out_dir "testcases.c") else None) nbwitnesses prog z3
) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | batch: Prims.bool -> out_dir: Prims.string -> name: Prims.string -> Main.process_files_t | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.string",
"Main.produce_z3_and_test_gen",
"FStar.Pervasives.Native.option",
"Prims.int",
"Z3TestGen.prog",
"Z3.Base.z3",
"Z3TestGen.do_test",
"Prims.unit",
"Options.get_z3_neg_test",
"Options.get_z3_pos_test",
"Prims.nat",
"Options.get_z3_branch_depth",
"Main.process_files_t"
] | [] | false | false | false | true | false | let produce_z3_and_test (batch: bool) (out_dir name: string) : Tot process_files_t =
| produce_z3_and_test_gen batch
out_dir
(fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_test out_dir
out_file
z3
prog
name
nbwitnesses
(Options.get_z3_branch_depth ())
(Options.get_z3_pos_test ())
(Options.get_z3_neg_test ())) | false |
Lib.IntTypes.fst | Lib.IntTypes.gte | val gte: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | val gte: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | let gte #t x y =
match t with
| U1 -> UInt8.gte x y
| U8 -> UInt8.gte x y
| U16 -> UInt16.gte x y
| U32 -> UInt32.gte x y
| U64 -> UInt64.gte x y
| U128 -> UInt128.gte x y
| S8 -> Int8.gte x y
| S16 -> Int16.gte x y
| S32 -> Int32.gte x y
| S64 -> Int64.gte x y
| S128 -> Int128.gte x y | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 1136,
"start_col": 0,
"start_line": 1124
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y
let mod_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let eq #t x y =
x = y
let eq_lemma #t x y = ()
let ne #t x y = not (eq x y)
let ne_lemma #t x y = ()
let lt #t x y =
match t with
| U1 -> UInt8.lt x y
| U8 -> UInt8.lt x y
| U16 -> UInt16.lt x y
| U32 -> UInt32.lt x y
| U64 -> UInt64.lt x y
| U128 -> UInt128.lt x y
| S8 -> Int8.lt x y
| S16 -> Int16.lt x y
| S32 -> Int32.lt x y
| S64 -> Int64.lt x y
| S128 -> Int128.lt x y
let lt_lemma #t x y = ()
let lte #t x y =
match t with
| U1 -> UInt8.lte x y
| U8 -> UInt8.lte x y
| U16 -> UInt16.lte x y
| U32 -> UInt32.lte x y
| U64 -> UInt64.lte x y
| U128 -> UInt128.lte x y
| S8 -> Int8.lte x y
| S16 -> Int16.lte x y
| S32 -> Int32.lte x y
| S64 -> Int64.lte x y
| S128 -> Int128.lte x y
let lte_lemma #t x y = ()
let gt #t x y =
match t with
| U1 -> UInt8.gt x y
| U8 -> UInt8.gt x y
| U16 -> UInt16.gt x y
| U32 -> UInt32.gt x y
| U64 -> UInt64.gt x y
| U128 -> UInt128.gt x y
| S8 -> Int8.gt x y
| S16 -> Int16.gt x y
| S32 -> Int32.gt x y
| S64 -> Int64.gt x y
| S128 -> Int128.gt x y
let gt_lemma #t x y = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> y: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"FStar.UInt8.gte",
"FStar.UInt16.gte",
"FStar.UInt32.gte",
"FStar.UInt64.gte",
"FStar.UInt128.gte",
"FStar.Int8.gte",
"FStar.Int16.gte",
"FStar.Int32.gte",
"FStar.Int64.gte",
"FStar.Int128.gte",
"Prims.bool"
] | [] | false | false | false | false | false | let gte #t x y =
| match t with
| U1 -> UInt8.gte x y
| U8 -> UInt8.gte x y
| U16 -> UInt16.gte x y
| U32 -> UInt32.gte x y
| U64 -> UInt64.gte x y
| U128 -> UInt128.gte x y
| S8 -> Int8.gte x y
| S16 -> Int16.gte x y
| S32 -> Int32.gte x y
| S64 -> Int64.gte x y
| S128 -> Int128.gte x y | false |
Vale.Math.Poly2.Galois.Lemmas.fsti | Vale.Math.Poly2.Galois.Lemmas.fmul | val fmul : a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f | let fmul (#f:G.field) (a b:G.felem f) = G.fmul #f a b | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 11,
"start_col": 7,
"start_line": 11
} | module Vale.Math.Poly2.Galois.Lemmas
open FStar.Mul
module I = Lib.IntTypes
module G = Spec.GaloisField
module P = Vale.Math.Poly2_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Galois | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Galois.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Galois.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Spec.GaloisField",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "Lib.IntTypes",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f | Prims.Tot | [
"total"
] | [] | [
"Spec.GaloisField.field",
"Spec.GaloisField.felem",
"Spec.GaloisField.fmul"
] | [] | false | false | false | false | false | let fmul (#f: G.field) (a b: G.felem f) =
| G.fmul #f a b | false |
|
Lib.IntTypes.fst | Lib.IntTypes.lt | val lt: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | val lt: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | let lt #t x y =
match t with
| U1 -> UInt8.lt x y
| U8 -> UInt8.lt x y
| U16 -> UInt16.lt x y
| U32 -> UInt32.lt x y
| U64 -> UInt64.lt x y
| U128 -> UInt128.lt x y
| S8 -> Int8.lt x y
| S16 -> Int16.lt x y
| S32 -> Int32.lt x y
| S64 -> Int64.lt x y
| S128 -> Int128.lt x y | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 1088,
"start_col": 0,
"start_line": 1076
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y
let mod_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let eq #t x y =
x = y
let eq_lemma #t x y = ()
let ne #t x y = not (eq x y)
let ne_lemma #t x y = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> y: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"FStar.UInt8.lt",
"FStar.UInt16.lt",
"FStar.UInt32.lt",
"FStar.UInt64.lt",
"FStar.UInt128.lt",
"FStar.Int8.lt",
"FStar.Int16.lt",
"FStar.Int32.lt",
"FStar.Int64.lt",
"FStar.Int128.lt",
"Prims.bool"
] | [] | false | false | false | false | false | let lt #t x y =
| match t with
| U1 -> UInt8.lt x y
| U8 -> UInt8.lt x y
| U16 -> UInt16.lt x y
| U32 -> UInt32.lt x y
| U64 -> UInt64.lt x y
| U128 -> UInt128.lt x y
| S8 -> Int8.lt x y
| S16 -> Int16.lt x y
| S32 -> Int32.lt x y
| S64 -> Int64.lt x y
| S128 -> Int128.lt x y | false |
Main.fst | Main.produce_and_postprocess_c | val produce_and_postprocess_c (out_dir file: string) : ML unit | val produce_and_postprocess_c (out_dir file: string) : ML unit | let produce_and_postprocess_c
(out_dir: string)
(file: string)
: ML unit
=
let modul = Options.get_module_name file in
let deps = Deps.collect_and_sort_dependencies [file] in
let dep_files_and_modules = List.map (fun f -> (f, Options.get_module_name f)) deps in
(* remove the current module from the deps *)
let dep_files_and_modules = List.filter (fun (_, m) -> m <> modul) dep_files_and_modules in
Batch.produce_and_postprocess_one_c
(Options.get_input_stream_binding ())
(Options.get_emit_output_types_defs ())
(Options.get_add_include ())
(Options.get_clang_format ())
(Options.get_clang_format_executable ())
out_dir
file
modul
dep_files_and_modules | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 25,
"end_line": 580,
"start_col": 0,
"start_line": 561
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false)
let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end
let build_and_run_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []
end
let with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit))
= if batch
then
let thr = Z3.with_z3_thread debug transcript f in
Some (fun _ ->
Z3.wait_for_z3_thread thr;
build_and_run_test_exe out_dir
)
else begin
Z3.with_z3 debug transcript f;
None
end
let produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let nbwitnesses = Options.get_z3_witnesses () in
let buf : ref string = alloc "" in
let prog = process_files_for_z3 (fun s -> buf := !buf ^ s) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
with_z3_thread_or batch out_dir (Options.get_debug ()) (Options.get_save_z3_transcript ()) (fun z3 ->
z3.to_z3 !buf;
do_test (if batch then Some (OS.concat out_dir "testcases.c") else None) nbwitnesses prog z3
)
let produce_z3_and_test
(batch: bool)
(out_dir: string)
(name: string)
: Tot process_files_t
= produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_test out_dir out_file z3 prog name nbwitnesses (Options.get_z3_branch_depth ()) (Options.get_z3_pos_test ()) (Options.get_z3_neg_test ())
)
let produce_z3_and_diff_test
(batch: bool)
(out_dir: string)
(names: (string & string))
: Tot process_files_t
=
let (name1, name2) = names in
produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_diff_test out_dir out_file z3 prog name1 name2 nbwitnesses (Options.get_z3_branch_depth ())
)
let produce_test_checker_exe
(batch: bool)
(out_dir: string)
(name1: string)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let prog = process_files_for_z3 (fun _ -> ()) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
Z3TestGen.produce_test_checker_exe (OS.concat out_dir "testcases.c") prog name1;
Some (fun _ ->
if batch then
build_test_exe out_dir
) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | out_dir: Prims.string -> file: Prims.string -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"Batch.produce_and_postprocess_one_c",
"Prims.unit",
"Options.get_clang_format_executable",
"Prims.bool",
"Options.get_clang_format",
"Prims.list",
"Options.get_add_include",
"Options.get_emit_output_types_defs",
"HashingOptions.input_stream_binding_t",
"Options.get_input_stream_binding",
"FStar.Pervasives.Native.tuple2",
"FStar.List.filter",
"Prims.op_disEquality",
"FStar.List.map",
"FStar.Pervasives.Native.Mktuple2",
"Options.get_module_name",
"Deps.collect_and_sort_dependencies",
"Prims.Cons",
"Prims.Nil"
] | [] | false | true | false | false | false | let produce_and_postprocess_c (out_dir file: string) : ML unit =
| let modul = Options.get_module_name file in
let deps = Deps.collect_and_sort_dependencies [file] in
let dep_files_and_modules = List.map (fun f -> (f, Options.get_module_name f)) deps in
let dep_files_and_modules = List.filter (fun (_, m) -> m <> modul) dep_files_and_modules in
Batch.produce_and_postprocess_one_c (Options.get_input_stream_binding ())
(Options.get_emit_output_types_defs ())
(Options.get_add_include ())
(Options.get_clang_format ())
(Options.get_clang_format_executable ())
out_dir
file
modul
dep_files_and_modules | false |
Vale.Math.Poly2.Galois.Lemmas.fsti | Vale.Math.Poly2.Galois.Lemmas.fadd | val fadd : a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f | let fadd (#f:G.field) (a b:G.felem f) = G.fadd #f a b | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.Lemmas.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 10,
"start_col": 7,
"start_line": 10
} | module Vale.Math.Poly2.Galois.Lemmas
open FStar.Mul
module I = Lib.IntTypes
module G = Spec.GaloisField
module P = Vale.Math.Poly2_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Galois | {
"checked_file": "/",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Galois.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Galois.Lemmas.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Spec.GaloisField",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "Lib.IntTypes",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"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": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f | Prims.Tot | [
"total"
] | [] | [
"Spec.GaloisField.field",
"Spec.GaloisField.felem",
"Spec.GaloisField.fadd"
] | [] | false | false | false | false | false | let fadd (#f: G.field) (a b: G.felem f) =
| G.fadd #f a b | false |
|
Main.fst | Main.produce_test_checker_exe | val produce_test_checker_exe (batch: bool) (out_dir name1: string) : Tot process_files_t | val produce_test_checker_exe (batch: bool) (out_dir name1: string) : Tot process_files_t | let produce_test_checker_exe
(batch: bool)
(out_dir: string)
(name1: string)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let prog = process_files_for_z3 (fun _ -> ()) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
Z3TestGen.produce_test_checker_exe (OS.concat out_dir "testcases.c") prog name1;
Some (fun _ ->
if batch then
build_test_exe out_dir
) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 559,
"start_col": 0,
"start_line": 544
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false)
let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end
let build_and_run_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []
end
let with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit))
= if batch
then
let thr = Z3.with_z3_thread debug transcript f in
Some (fun _ ->
Z3.wait_for_z3_thread thr;
build_and_run_test_exe out_dir
)
else begin
Z3.with_z3 debug transcript f;
None
end
let produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let nbwitnesses = Options.get_z3_witnesses () in
let buf : ref string = alloc "" in
let prog = process_files_for_z3 (fun s -> buf := !buf ^ s) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
with_z3_thread_or batch out_dir (Options.get_debug ()) (Options.get_save_z3_transcript ()) (fun z3 ->
z3.to_z3 !buf;
do_test (if batch then Some (OS.concat out_dir "testcases.c") else None) nbwitnesses prog z3
)
let produce_z3_and_test
(batch: bool)
(out_dir: string)
(name: string)
: Tot process_files_t
= produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_test out_dir out_file z3 prog name nbwitnesses (Options.get_z3_branch_depth ()) (Options.get_z3_pos_test ()) (Options.get_z3_neg_test ())
)
let produce_z3_and_diff_test
(batch: bool)
(out_dir: string)
(names: (string & string))
: Tot process_files_t
=
let (name1, name2) = names in
produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_diff_test out_dir out_file z3 prog name1 name2 nbwitnesses (Options.get_z3_branch_depth ())
) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | batch: Prims.bool -> out_dir: Prims.string -> name1: Prims.string -> Main.process_files_t | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.string",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Some",
"Prims.unit",
"Main.build_test_exe",
"FStar.Pervasives.Native.option",
"Z3TestGen.produce_test_checker_exe",
"OS.concat",
"Z3TestGen.prog",
"Main.process_files_for_z3",
"FStar.Pervasives.Native.None",
"Main.process_files_t"
] | [] | false | false | false | true | false | let produce_test_checker_exe (batch: bool) (out_dir name1: string) : Tot process_files_t =
| fun
(files_and_modules: list (string & string))
(emit_fstar: (string -> ML bool))
(emit_output_types_defs: bool)
->
let prog =
process_files_for_z3 (fun _ -> ())
files_and_modules
(if batch then Some emit_fstar else None)
emit_output_types_defs
in
Z3TestGen.produce_test_checker_exe (OS.concat out_dir "testcases.c") prog name1;
Some (fun _ -> if batch then build_test_exe out_dir) | false |
Lib.IntTypes.fst | Lib.IntTypes.neq_mask_lemma | val neq_mask_lemma: #t:inttype{~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (neq_mask a b) == 0
else v (neq_mask a b) == ones_v t)
[SMTPat (neq_mask #t a b)] | val neq_mask_lemma: #t:inttype{~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (neq_mask a b) == 0
else v (neq_mask a b) == ones_v t)
[SMTPat (neq_mask #t a b)] | let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 884,
"start_col": 0,
"start_line": 879
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.v a = Lib.IntTypes.v b with
| true -> Lib.IntTypes.v (Lib.IntTypes.neq_mask a b) == 0
| _ -> Lib.IntTypes.v (Lib.IntTypes.neq_mask a b) == Lib.IntTypes.ones_v t)
<:
Type0)) [SMTPat (Lib.IntTypes.neq_mask a b)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.lognot",
"Lib.IntTypes.u1",
"FStar.UInt.lognot_self",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.UInt.lognot_lemma_1"
] | [] | false | false | true | false | false | let neq_mask_lemma #t a b =
| match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0 | false |
Lib.IntTypes.fst | Lib.IntTypes.gt | val gt: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | val gt: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | let gt #t x y =
match t with
| U1 -> UInt8.gt x y
| U8 -> UInt8.gt x y
| U16 -> UInt16.gt x y
| U32 -> UInt32.gt x y
| U64 -> UInt64.gt x y
| U128 -> UInt128.gt x y
| S8 -> Int8.gt x y
| S16 -> Int16.gt x y
| S32 -> Int32.gt x y
| S64 -> Int64.gt x y
| S128 -> Int128.gt x y | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 1120,
"start_col": 0,
"start_line": 1108
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y
let mod_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let eq #t x y =
x = y
let eq_lemma #t x y = ()
let ne #t x y = not (eq x y)
let ne_lemma #t x y = ()
let lt #t x y =
match t with
| U1 -> UInt8.lt x y
| U8 -> UInt8.lt x y
| U16 -> UInt16.lt x y
| U32 -> UInt32.lt x y
| U64 -> UInt64.lt x y
| U128 -> UInt128.lt x y
| S8 -> Int8.lt x y
| S16 -> Int16.lt x y
| S32 -> Int32.lt x y
| S64 -> Int64.lt x y
| S128 -> Int128.lt x y
let lt_lemma #t x y = ()
let lte #t x y =
match t with
| U1 -> UInt8.lte x y
| U8 -> UInt8.lte x y
| U16 -> UInt16.lte x y
| U32 -> UInt32.lte x y
| U64 -> UInt64.lte x y
| U128 -> UInt128.lte x y
| S8 -> Int8.lte x y
| S16 -> Int16.lte x y
| S32 -> Int32.lte x y
| S64 -> Int64.lte x y
| S128 -> Int128.lte x y
let lte_lemma #t x y = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> y: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"FStar.UInt8.gt",
"FStar.UInt16.gt",
"FStar.UInt32.gt",
"FStar.UInt64.gt",
"FStar.UInt128.gt",
"FStar.Int8.gt",
"FStar.Int16.gt",
"FStar.Int32.gt",
"FStar.Int64.gt",
"FStar.Int128.gt",
"Prims.bool"
] | [] | false | false | false | false | false | let gt #t x y =
| match t with
| U1 -> UInt8.gt x y
| U8 -> UInt8.gt x y
| U16 -> UInt16.gt x y
| U32 -> UInt32.gt x y
| U64 -> UInt64.gt x y
| U128 -> UInt128.gt x y
| S8 -> Int8.gt x y
| S16 -> Int16.gt x y
| S32 -> Int32.gt x y
| S64 -> Int64.gt x y
| S128 -> Int128.gt x y | false |
Main.fst | Main.emit_entrypoint | val emit_entrypoint
(produce_ep_error: Target.opt_produce_everparse_error)
(en: env)
(modul: string)
(t_decls: list Target.decl)
(static_asserts: StaticAssertions.static_asserts)
(emit_output_types_defs: bool)
: ML unit | val emit_entrypoint
(produce_ep_error: Target.opt_produce_everparse_error)
(en: env)
(modul: string)
(t_decls: list Target.decl)
(static_asserts: StaticAssertions.static_asserts)
(emit_output_types_defs: bool)
: ML unit | let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 342,
"start_col": 0,
"start_line": 219
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
() | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
produce_ep_error: Target.opt_produce_everparse_error ->
en: Main.env ->
modul: Prims.string ->
t_decls: Prims.list Target.decl ->
static_asserts: StaticAssertions.static_asserts ->
emit_output_types_defs: Prims.bool
-> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Target.opt_produce_everparse_error",
"Main.env",
"Prims.string",
"Prims.list",
"Target.decl",
"StaticAssertions.static_asserts",
"Prims.bool",
"StaticAssertions.has_static_asserts",
"FStar.IO.close_write_file",
"Prims.unit",
"FStar.IO.write_string",
"StaticAssertions.print_static_asserts",
"FStar.IO.fd_write",
"Main.open_write_file",
"FStar.Printf.sprintf",
"Options.get_output_dir",
"Target.print_out_exprs_c",
"Prims.op_AmpAmp",
"Prims.op_Negation",
"Options.make_includes",
"Target.print_output_types_defs",
"Target.has_extern_types",
"Target.has_output_type_exprs",
"Target.has_output_types",
"FStar.Pervasives.Native.tuple2",
"Target.print_c_entry",
"Main.__proj__Mkenv__item__binding_env",
"FStar.Pervasives.Native.uu___is_Some",
"Target.decl'",
"Target.decl_attributes",
"FStar.Pervasives.Native.option",
"FStar.List.tryFind",
"Target.type_decl",
"Target.__proj__Mktypedef_name__item__td_entrypoint",
"Target.__proj__Mktype_decl__item__decl_name"
] | [] | false | true | false | false | false | let emit_entrypoint
(produce_ep_error: Target.opt_produce_everparse_error)
(en: env)
(modul: string)
(t_decls: list Target.decl)
(static_asserts: StaticAssertions.static_asserts)
(emit_output_types_defs: bool)
: ML unit =
| if
List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false)
t_decls |>
Some?
then
(let wrapper_header, wrapper_impl =
Target.print_c_entry produce_ep_error modul en.binding_env t_decls
in
let c_file =
open_write_file (Printf.sprintf "%s/%sWrapper.c" (Options.get_output_dir ()) modul)
in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file (Printf.sprintf "%s/%sWrapper.h" (Options.get_output_dir ()) modul)
in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file);
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
if emit_output_types_defs
then
(if has_output_types
then
(let output_types_defs_file =
open_write_file (Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul)
in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file);
if has_output_types && not has_extern_types
then
let extern_typedefs_file =
open_write_file (Printf.sprintf "%s/%s_ExternalTypedefs.h" (Options.get_output_dir ()) modul
)
in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf "#ifndef __%s_ExternalTypedefs_H\n#define __%s_ExternalTypedefs_H\n\r\n #if defined(__cplusplus)\nextern \"C\" {\n#endif\n\n\n%s#include \"%s_OutputTypesDefs.h\"\n\n#if defined(__cplusplus)\n}\n#endif\n\n#define __%s_ExternalTypedefs_H_DEFINED\n#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file);
if has_out_exprs
then
(let output_types_c_file =
open_write_file (Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul)
in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file);
if StaticAssertions.has_static_asserts static_asserts
then
let c_static_asserts_file =
open_write_file (Printf.sprintf "%s/%sStaticAssertions.c" (Options.get_output_dir ()) modul)
in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file | false |
Lib.IntTypes.fst | Lib.IntTypes.mod_mask_value | val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1) | val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1) | let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 956,
"start_col": 0,
"start_line": 951
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: Lib.IntTypes.shiftval t {Prims.pow2 (Lib.IntTypes.uint_v m) <= Lib.IntTypes.maxint t}
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.mod_mask m) == Prims.pow2 (Lib.IntTypes.v m) - 1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.shiftval",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.pow2",
"Lib.IntTypes.uint_v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.maxint",
"FStar.Math.Lemmas.small_modulo_lemma_1",
"Prims.op_Subtraction",
"Lib.IntTypes.v",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.Math.Lemmas.pow2_lt_compat",
"FStar.Math.Lemmas.pow2_double_mult",
"Lib.IntTypes.shift_left_lemma",
"Lib.IntTypes.mk_int"
] | [] | true | false | true | false | false | let mod_mask_value #t #l m =
| shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t)) | false |
Main.fst | Main.parse_check_and_desugar | val parse_check_and_desugar (pa: opt_prune_actions) (en: env) (mname fn: string)
: ML (list Ast.decl & StaticAssertions.static_asserts & env) | val parse_check_and_desugar (pa: opt_prune_actions) (en: env) (mname fn: string)
: ML (list Ast.decl & StaticAssertions.static_asserts & env) | let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 4,
"end_line": 117,
"start_col": 0,
"start_line": 51
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | pa: Main.opt_prune_actions -> en: Main.env -> mname: Prims.string -> fn: Prims.string
-> FStar.All.ML ((Prims.list Ast.decl * StaticAssertions.static_asserts) * Main.env) | FStar.All.ML | [
"ml"
] | [] | [
"Main.opt_prune_actions",
"Main.env",
"Prims.string",
"Prims.list",
"Ast.decl",
"FStar.Pervasives.Native.option",
"Ast.type_refinement",
"GlobalEnv.global_env",
"FStar.Pervasives.Native.Mktuple3",
"StaticAssertions.static_asserts",
"Main.Mkenv",
"Main.__proj__Mkenv__item__typesizes_env",
"Main.__proj__Mkenv__item__translate_env",
"FStar.Pervasives.Native.tuple3",
"Prims.unit",
"Options.debug_print_string",
"Ast.print_decls",
"InlineSingletonRecords.simplify_prog",
"Simplify.simplify_prog",
"StaticAssertions.compute_static_asserts",
"TypeSizes.size_of_decls",
"BitFields.eliminate_decls",
"FStar.IO.print_string",
"JSON.prog_to_json",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Options.get_json",
"FStar.Pervasives.Native.tuple2",
"Binding.bind_decls",
"Main.__proj__Mkenv__item__binding_env",
"Ast.prog",
"Desugar.desugar",
"Prims.op_Equality",
"Main.prune_actions",
"FStar.Pervasives.Native.Some",
"Main.PruneActions",
"Ast.prog_prune_actions",
"Main.parse_prog",
"FStar.Printf.sprintf"
] | [] | false | true | false | false | false | let parse_check_and_desugar (pa: opt_prune_actions) (en: env) (mname fn: string)
: ML (list Ast.decl & StaticAssertions.static_asserts & env) =
| Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions then prog_prune_actions p else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json ()
then
(IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n");
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = { en with binding_env = benv } in
decls, static_asserts, en | false |
Hacl.Impl.K256.Verify.fst | Hacl.Impl.K256.Verify.lbytes | val lbytes : len: Lib.IntTypes.size_t -> Type0 | let lbytes len = lbuffer uint8 len | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"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.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"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 | len: Lib.IntTypes.size_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8"
] | [] | false | false | false | true | true | let lbytes len =
| lbuffer uint8 len | false |
|
FStar.Int.fst | FStar.Int.pow2_values | val pow2_values: x:nat -> Lemma
(let p = pow2 x in
match x with
| 0 -> p=1
| 1 -> p=2
| 8 -> p=256
| 16 -> p=65536
| 31 -> p=2147483648
| 32 -> p=4294967296
| 63 -> p=9223372036854775808
| 64 -> p=18446744073709551616
| _ -> True)
[SMTPat (pow2 x)] | val pow2_values: x:nat -> Lemma
(let p = pow2 x in
match x with
| 0 -> p=1
| 1 -> p=2
| 8 -> p=256
| 16 -> p=65536
| 31 -> p=2147483648
| 32 -> p=4294967296
| 63 -> p=9223372036854775808
| 64 -> p=18446744073709551616
| _ -> True)
[SMTPat (pow2 x)] | 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)
| _ -> () | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 35,
"start_col": 0,
"start_line": 25
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
{
"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 | x: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(let p = Prims.pow2 x in
(match x with
| 0 -> p = 1
| 1 -> p = 2
| 8 -> p = 256
| 16 -> p = 65536
| 31 -> p = 2147483648
| 32 -> p = 4294967296
| 63 -> p = 9223372036854775808
| 64 -> p = 18446744073709551616
| _ -> Prims.l_True)
<:
Type0)) [SMTPat (Prims.pow2 x)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"Prims.unit"
] | [] | false | false | true | false | false | 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)
| _ -> () | false |
FStar.Int.fst | FStar.Int.mul_underspec | val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a * b) n ==> a * b = c)) | val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a * b) n ==> a * b = c)) | let mul_underspec #n a b =
if fits (a*b) n then a * b else 0 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 50,
"start_col": 0,
"start_line": 49
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
{
"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.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | Prims.Pure | [] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.fits",
"FStar.Mul.op_Star",
"Prims.bool"
] | [] | false | false | false | false | false | let mul_underspec #n a b =
| if fits (a * b) n then a * b else 0 | false |
FStar.Int.fst | FStar.Int.incr_underspec | val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a < max_int n)))
(ensures (fun b -> a + 1 = b)) | val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a < max_int n)))
(ensures (fun b -> a + 1 = b)) | let incr_underspec #n a =
if a < max_int n then a + 1 else 0 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 38,
"start_col": 0,
"start_line": 37
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
{
"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.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | Prims.Pure | [] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.op_LessThan",
"FStar.Int.max_int",
"Prims.op_Addition",
"Prims.bool"
] | [] | false | false | false | false | false | let incr_underspec #n a =
| if a < max_int n then a + 1 else 0 | false |
Main.fst | Main.produce_z3_and_test_gen | val produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: (option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit))
: Tot process_files_t | val produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: (option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit))
: Tot process_files_t | let produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let nbwitnesses = Options.get_z3_witnesses () in
let buf : ref string = alloc "" in
let prog = process_files_for_z3 (fun s -> buf := !buf ^ s) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
with_z3_thread_or batch out_dir (Options.get_debug ()) (Options.get_save_z3_transcript ()) (fun z3 ->
z3.to_z3 !buf;
do_test (if batch then Some (OS.concat out_dir "testcases.c") else None) nbwitnesses prog z3
) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 522,
"start_col": 0,
"start_line": 506
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false)
let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end
let build_and_run_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []
end
let with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit))
= if batch
then
let thr = Z3.with_z3_thread debug transcript f in
Some (fun _ ->
Z3.wait_for_z3_thread thr;
build_and_run_test_exe out_dir
)
else begin
Z3.with_z3 debug transcript f;
None
end | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
batch: Prims.bool ->
out_dir: Prims.string ->
do_test:
(
_: FStar.Pervasives.Native.option Prims.string ->
_: Prims.int ->
_: Z3TestGen.prog ->
_: Z3.Base.z3
-> FStar.All.ML Prims.unit)
-> Main.process_files_t | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.string",
"FStar.Pervasives.Native.option",
"Prims.int",
"Z3TestGen.prog",
"Z3.Base.z3",
"Prims.unit",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Main.with_z3_thread_or",
"FStar.Pervasives.Native.Some",
"OS.concat",
"FStar.Pervasives.Native.None",
"Z3.Base.__proj__Mkz3__item__to_z3",
"FStar.ST.op_Bang",
"FStar.Heap.trivial_preorder",
"Options.get_save_z3_transcript",
"Options.get_debug",
"Main.process_files_for_z3",
"FStar.ST.op_Colon_Equals",
"Prims.op_Hat",
"FStar.ST.ref",
"FStar.ST.alloc",
"FStar.ST.mref",
"Prims.pos",
"Options.get_z3_witnesses",
"Main.process_files_t"
] | [] | false | false | false | false | false | let produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: (option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit))
: Tot process_files_t =
| fun
(files_and_modules: list (string & string))
(emit_fstar: (string -> ML bool))
(emit_output_types_defs: bool)
->
let nbwitnesses = Options.get_z3_witnesses () in
let buf:ref string = alloc "" in
let prog =
process_files_for_z3 (fun s -> buf := !buf ^ s)
files_and_modules
(if batch then Some emit_fstar else None)
emit_output_types_defs
in
with_z3_thread_or batch
out_dir
(Options.get_debug ())
(Options.get_save_z3_transcript ())
(fun z3 ->
z3.to_z3 !buf;
do_test (if batch then Some (OS.concat out_dir "testcases.c") else None) nbwitnesses prog z3
) | false |
FStar.Int.fst | FStar.Int.decr_underspec | val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a > min_int n)))
(ensures (fun b -> a - 1 = b)) | val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a > min_int n)))
(ensures (fun b -> a - 1 = b)) | let decr_underspec #n a =
if a > min_int n then a - 1 else 0 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 41,
"start_col": 0,
"start_line": 40
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
{
"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.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | Prims.Pure | [] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.op_GreaterThan",
"FStar.Int.min_int",
"Prims.op_Subtraction",
"Prims.bool"
] | [] | false | false | false | false | false | let decr_underspec #n a =
| if a > min_int n then a - 1 else 0 | false |
FStar.Int.fst | FStar.Int.div_underspec | val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n)
(requires True)
(ensures (fun c ->
(b <> 0 /\ size (a / b) n) ==> a / b = c)) | val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n)
(requires True)
(ensures (fun c ->
(b <> 0 /\ size (a / b) n) ==> a / b = c)) | let div_underspec #n a b =
if fits (a / b) n then a / b else 0 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 53,
"start_col": 0,
"start_line": 52
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
{
"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.Int.int_t n -> b: FStar.Int.int_t n {b <> 0} -> Prims.Pure (FStar.Int.int_t n) | Prims.Pure | [] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"FStar.Int.fits",
"FStar.Int.op_Slash",
"Prims.bool"
] | [] | false | false | false | false | false | let div_underspec #n a b =
| if fits (a / b) n then a / b else 0 | false |
FStar.Int.fst | FStar.Int.add_underspec | val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a + b) n ==> a + b = c)) | val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a + b) n ==> a + b = c)) | let add_underspec #n a b =
if fits (a+b) n then a + b else 0 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 44,
"start_col": 0,
"start_line": 43
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
{
"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.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | Prims.Pure | [] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.fits",
"Prims.op_Addition",
"Prims.bool"
] | [] | false | false | false | false | false | let add_underspec #n a b =
| if fits (a + b) n then a + b else 0 | false |
Main.fst | Main.emit_fstar_code_for_interpreter | val emit_fstar_code_for_interpreter
(en: env)
(modul: string)
(tds: list T.decl)
(itds: list InterpreterTarget.decl)
(all_modules: list string)
: ML unit | val emit_fstar_code_for_interpreter
(en: env)
(modul: string)
(tds: list T.decl)
(itds: list InterpreterTarget.decl)
(all_modules: list string)
: ML unit | let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
() | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 217,
"start_col": 0,
"start_line": 143
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
en: Main.env ->
modul: Prims.string ->
tds: Prims.list Target.decl ->
itds: Prims.list InterpreterTarget.decl ->
all_modules: Prims.list Prims.string
-> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Main.env",
"Prims.string",
"Prims.list",
"Target.decl",
"InterpreterTarget.decl",
"TranslateForInterpreter.translate_env",
"InterpreterTarget.env",
"Prims.unit",
"FStar.IO.close_write_file",
"FStar.IO.write_string",
"FStar.IO.fd_write",
"Main.open_write_file",
"FStar.Printf.sprintf",
"Options.get_output_dir",
"FStar.String.concat",
"Prims.bool",
"Target.print_external_api_fstar_interpreter",
"Target.has_external_api",
"Target.print_external_types_fstar_interpreter",
"Prims.op_BarBar",
"Target.has_output_types",
"Target.has_extern_types",
"FStar.Pervasives.Native.tuple2",
"InterpreterTarget.print_decls",
"Main.__proj__Mkenv__item__translate_env"
] | [] | false | true | false | false | false | let emit_fstar_code_for_interpreter
(en: env)
(modul: string)
(tds: list T.decl)
(itds: list InterpreterTarget.decl)
(all_modules: list string)
: ML unit =
| let _, en = en.translate_env in
let impl, iface = InterpreterTarget.print_decls en modul itds in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then
(let external_types_fsti_file =
open_write_file (Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul)
in
FStar.IO.write_string external_types_fsti_file
(Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file);
let has_external_api = T.has_external_api tds in
if has_external_api
then
(let external_api_fsti_file =
open_write_file (Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul)
in
FStar.IO.write_string external_api_fsti_file
(Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file);
let maybe_open_external_api =
if has_external_api then Printf.sprintf "open %s.ExternalAPI" modul else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\nopen EverParse3d.Prelude\nopen EverParse3d.Actions.All\nopen EverParse3d.Interpreter\n%s\nmodule T = FStar.Tactics\nmodule A = EverParse3d.Actions.All\nmodule P = EverParse3d.Prelude\n#push-options \"--fuel 0 --ifuel 0\"\n#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 FStar.UInt16 FStar.UInt32 FStar.UInt64 EverParse3d FStar.Int.Cast %s'\"\n"
modul
maybe_open_external_api
(all_modules |> String.concat " ")
in
let fst_file = open_write_file (Printf.sprintf "%s/%s.fst" (Options.get_output_dir ()) modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file = open_write_file (Printf.sprintf "%s/%s.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
() | false |
FStar.Int.fst | FStar.Int.sub_underspec | val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a - b) n ==> a - b = c)) | val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a - b) n ==> a - b = c)) | let sub_underspec #n a b =
if fits (a-b) n then a - b else 0 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 47,
"start_col": 0,
"start_line": 46
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
{
"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.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | Prims.Pure | [] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.fits",
"Prims.op_Subtraction",
"Prims.bool"
] | [] | false | false | false | false | false | let sub_underspec #n a b =
| if fits (a - b) n then a - b else 0 | false |
Pulse.Checker.AssertWithBinders.fst | Pulse.Checker.AssertWithBinders.is_host_term | val is_host_term : t: FStar.Stubs.Reflection.Types.term -> Prims.bool | let is_host_term (t:R.term) = not (R.Tv_Unknown? (R.inspect_ln t)) | {
"file_name": "lib/steel/pulse/Pulse.Checker.AssertWithBinders.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 66,
"end_line": 37,
"start_col": 0,
"start_line": 37
} | (*
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.AssertWithBinders
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Elaborate.Pure
open Pulse.Typing.Env
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module PC = Pulse.Checker.Pure
module P = Pulse.Syntax.Printer
module N = Pulse.Syntax.Naming
module PS = Pulse.Checker.Prover.Substs
module Prover = Pulse.Checker.Prover
module Env = Pulse.Typing.Env
open Pulse.Show
module RU = Pulse.RuntimeUtils | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Show.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.AssertWithBinders.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Show",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover",
"short_module": "Prover"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Naming",
"short_module": "N"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Pure",
"short_module": "PC"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"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": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"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 | t: FStar.Stubs.Reflection.Types.term -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.op_Negation",
"FStar.Stubs.Reflection.V2.Data.uu___is_Tv_Unknown",
"FStar.Stubs.Reflection.V2.Builtins.inspect_ln",
"Prims.bool"
] | [] | false | false | false | true | false | let is_host_term (t: R.term) =
| not (R.Tv_Unknown? (R.inspect_ln t)) | false |
|
FStar.Int.fst | FStar.Int.div_size | val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} ->
Lemma (requires (size a n)) (ensures (size (a / b) n)) | val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} ->
Lemma (requires (size a n)) (ensures (size (a / b) n)) | let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b) | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 56,
"start_col": 0,
"start_line": 55
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
{
"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.Int.int_t n {FStar.Int.min_int n < a} -> b: FStar.Int.int_t n {b <> 0}
-> FStar.Pervasives.Lemma (requires FStar.Int.size a n) (ensures FStar.Int.size (a / b) n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.min_int",
"Prims.op_disEquality",
"Prims.int",
"FStar.Math.Lib.slash_decr_axiom",
"Prims.abs",
"Prims.unit"
] | [] | true | false | true | false | false | let div_size #n a b =
| FStar.Math.Lib.slash_decr_axiom (abs a) (abs b) | false |
FStar.Int.fst | FStar.Int.to_vec_lemma_2 | val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) | val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) | let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b) | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 65,
"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 FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Base.equal (FStar.Int.to_vec a) (FStar.Int.to_vec b)) (ensures a = b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.UInt.to_vec_lemma_2",
"FStar.Int.to_uint",
"Prims.unit"
] | [] | true | false | true | false | false | let to_vec_lemma_2 #n a b =
| UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b) | false |
Pulse.Checker.AssertWithBinders.fst | Pulse.Checker.AssertWithBinders.debug_log | val debug_log : g: Pulse.Typing.Env.env -> f: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.string)
-> FStar.Tactics.Effect.Tac Prims.unit | let debug_log = Pulse.Typing.debug_log "with_binders" | {
"file_name": "lib/steel/pulse/Pulse.Checker.AssertWithBinders.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 53,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | (*
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.AssertWithBinders
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Elaborate.Pure
open Pulse.Typing.Env
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module PC = Pulse.Checker.Pure
module P = Pulse.Syntax.Printer
module N = Pulse.Syntax.Naming
module PS = Pulse.Checker.Prover.Substs
module Prover = Pulse.Checker.Prover
module Env = Pulse.Typing.Env
open Pulse.Show
module RU = Pulse.RuntimeUtils
let is_host_term (t:R.term) = not (R.Tv_Unknown? (R.inspect_ln t)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Show.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.AssertWithBinders.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Show",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover",
"short_module": "Prover"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Naming",
"short_module": "N"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Pure",
"short_module": "PC"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"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": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"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 -> f: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.string)
-> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.debug_log"
] | [] | false | true | false | false | false | let debug_log =
| Pulse.Typing.debug_log "with_binders" | false |
|
Pulse.Checker.AssertWithBinders.fst | Pulse.Checker.AssertWithBinders.visit_and_rewrite_conjuncts | val visit_and_rewrite_conjuncts (p: (R.term & R.term)) (tms: list term) : T.Tac (list term) | val visit_and_rewrite_conjuncts (p: (R.term & R.term)) (tms: list term) : T.Tac (list term) | let visit_and_rewrite_conjuncts (p: (R.term & R.term)) (tms:list term) : T.Tac (list term) =
T.map (visit_and_rewrite p) tms | {
"file_name": "lib/steel/pulse/Pulse.Checker.AssertWithBinders.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 33,
"end_line": 198,
"start_col": 0,
"start_line": 197
} | (*
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.AssertWithBinders
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Elaborate.Pure
open Pulse.Typing.Env
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module PC = Pulse.Checker.Pure
module P = Pulse.Syntax.Printer
module N = Pulse.Syntax.Naming
module PS = Pulse.Checker.Prover.Substs
module Prover = Pulse.Checker.Prover
module Env = Pulse.Typing.Env
open Pulse.Show
module RU = Pulse.RuntimeUtils
let is_host_term (t:R.term) = not (R.Tv_Unknown? (R.inspect_ln t))
let debug_log = Pulse.Typing.debug_log "with_binders"
let option_must (f:option 'a) (msg:string) : T.Tac 'a =
match f with
| Some x -> x
| None -> T.fail msg
let rec refl_abs_binders (t:R.term) (acc:list binder) : T.Tac (list binder) =
let open R in
match inspect_ln t with
| Tv_Abs b body ->
let {sort; ppname} = R.inspect_binder b in
let sort = option_must (readback_ty sort)
(Printf.sprintf "Failed to readback elaborated binder sort %s in refl_abs_binders"
(T.term_to_string sort)) in
refl_abs_binders body
((mk_binder_ppname sort (mk_ppname ppname (RU.range_of_term t)))::acc)
| _ -> L.rev acc
let infer_binder_types (g:env) (bs:list binder) (v:vprop)
: T.Tac (list binder) =
match bs with
| [] -> []
| _ ->
let g = push_context g "infer_binder_types" v.range in
let tv = elab_term v in
if not (is_host_term tv)
then fail g (Some v.range)
(Printf.sprintf "assert.infer_binder_types: elaborated %s to %s, which failed the host term check"
(P.term_to_string v) (T.term_to_string tv));
let as_binder (b:binder) : R.binder =
let open R in
let bv : binder_view =
{ sort = elab_term b.binder_ty;
ppname = b.binder_ppname.name;
qual = Q_Explicit;
attrs = [] } in
pack_binder bv
in
let abstraction =
L.fold_right
(fun b (tv:host_term) ->
let b = as_binder b in
R.pack_ln (R.Tv_Abs b tv))
bs
tv
in
let inst_abstraction, _ = PC.instantiate_term_implicits g (tm_fstar abstraction v.range) in
match inst_abstraction.t with
| Tm_FStar t -> refl_abs_binders t []
| _ -> T.fail "Impossible: instantiated abstraction is not embedded F* term, please file a bug-report"
let rec open_binders (g:env) (bs:list binder) (uvs:env { disjoint uvs g }) (v:term) (body:st_term)
: T.Tac (uvs:env { disjoint uvs g } & term & st_term) =
match bs with
| [] -> (| uvs, v, body |)
| b::bs ->
// these binders are only lax checked so far
let _ = PC.check_universe (push_env g uvs) b.binder_ty in
let x = fresh (push_env g uvs) in
let ss = [ DT 0 (tm_var {nm_index=x;nm_ppname=b.binder_ppname}) ] in
let bs = L.mapi (fun i b ->
assume (i >= 0);
subst_binder b (shift_subst_n i ss)) bs in
let v = subst_term v (shift_subst_n (L.length bs) ss) in
let body = subst_st_term body (shift_subst_n (L.length bs) ss) in
open_binders g bs (push_binding uvs x b.binder_ppname b.binder_ty) v body
let closing (bs:list (ppname & var & typ)) : subst =
L.fold_right (fun (_, x, _) (n, ss) ->
n+1,
(ND x n)::ss
) bs (0, []) |> snd
let rec close_binders (bs:list (ppname & var & typ))
: Tot (list binder) (decreases L.length bs) =
match bs with
| [] -> []
| (name, x, t)::bs ->
let bss = L.mapi (fun n (n1, x1, t1) ->
assume (n >= 0);
n1, x1, subst_term t1 [ND x n]) bs in
let b = mk_binder_ppname t name in
assume (L.length bss == L.length bs);
b::(close_binders bss)
let unfold_defs (g:env) (defs:option (list string)) (t:term)
: T.Tac term
= let t = elab_term t in
let head, _ = T.collect_app t in
match R.inspect_ln head with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
let head = String.concat "." (R.inspect_fv fv) in
let fully =
match defs with
| Some defs -> defs
| None -> []
in
let rt = RU.unfold_def (fstar_env g) head fully t in
let rt = option_must rt
(Printf.sprintf "unfolding %s returned None" (T.term_to_string t)) in
let ty = option_must (readback_ty rt)
(Printf.sprintf "error in reading back the unfolded term %s" (T.term_to_string rt)) in
debug_log g (fun _ -> Printf.sprintf "Unfolded %s to F* term %s and readback as %s" (T.term_to_string t) (T.term_to_string rt) (P.term_to_string ty));
ty
)
| _ ->
fail g (Some (RU.range_of_term t))
(Printf.sprintf "Cannot unfold %s, the head is not an fvar" (T.term_to_string t))
let check_unfoldable g (v:term) : T.Tac unit =
match v.t with
| Tm_FStar _ -> ()
| _ ->
fail g
(Some v.range)
(Printf.sprintf "`fold` and `unfold` expect a single user-defined predicate as an argument, \
but %s is a primitive term that cannot be folded or unfolded"
(P.term_to_string v))
let visit_and_rewrite (p: (R.term & R.term)) (t:term) : T.Tac term =
let open FStar.Reflection.V2.TermEq in
let lhs, rhs = p in
let visitor (t:R.term) : T.Tac R.term =
if term_eq t lhs then rhs else t
in
match R.inspect_ln lhs with
| R.Tv_Var n -> (
let nv = R.inspect_namedv n in
assume (is_host_term rhs);
subst_term t [NT nv.uniq { t = Tm_FStar rhs; range = t.range }]
)
| _ ->
let rec aux (t:term) : T.Tac term =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Inames
| Tm_Unknown -> t
| Tm_Inv i ->
{ t with t = Tm_Inv (aux i) }
| Tm_AddInv i is ->
{ t with t = Tm_AddInv (aux i) (aux is) }
| Tm_Pure p -> { t with t = Tm_Pure (aux p) }
| Tm_Star l r -> { t with t = Tm_Star (aux l) (aux r) }
| Tm_ExistsSL u b body -> { t with t = Tm_ExistsSL u { b with binder_ty=aux b.binder_ty} (aux body) }
| Tm_ForallSL u b body -> { t with t = Tm_ForallSL u { b with binder_ty=aux b.binder_ty} (aux body) }
| Tm_FStar h ->
let h = FStar.Tactics.Visit.visit_tm visitor h in
assume (is_host_term h);
{ t with t=Tm_FStar h }
in
aux t | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Show.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.AssertWithBinders.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Show",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover",
"short_module": "Prover"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Naming",
"short_module": "N"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Pure",
"short_module": "PC"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"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": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"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 |
p: (FStar.Stubs.Reflection.Types.term * FStar.Stubs.Reflection.Types.term) ->
tms: Prims.list Pulse.Syntax.Base.term
-> FStar.Tactics.Effect.Tac (Prims.list Pulse.Syntax.Base.term) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"Pulse.Syntax.Base.term",
"FStar.Tactics.Util.map",
"Pulse.Checker.AssertWithBinders.visit_and_rewrite"
] | [] | false | true | false | false | false | let visit_and_rewrite_conjuncts (p: (R.term & R.term)) (tms: list term) : T.Tac (list term) =
| T.map (visit_and_rewrite p) tms | false |
Main.fst | Main.produce_z3_and_diff_test | val produce_z3_and_diff_test (batch: bool) (out_dir: string) (names: (string & string))
: Tot process_files_t | val produce_z3_and_diff_test (batch: bool) (out_dir: string) (names: (string & string))
: Tot process_files_t | let produce_z3_and_diff_test
(batch: bool)
(out_dir: string)
(names: (string & string))
: Tot process_files_t
=
let (name1, name2) = names in
produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_diff_test out_dir out_file z3 prog name1 name2 nbwitnesses (Options.get_z3_branch_depth ())
) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 542,
"start_col": 0,
"start_line": 533
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false)
let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end
let build_and_run_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []
end
let with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit))
= if batch
then
let thr = Z3.with_z3_thread debug transcript f in
Some (fun _ ->
Z3.wait_for_z3_thread thr;
build_and_run_test_exe out_dir
)
else begin
Z3.with_z3 debug transcript f;
None
end
let produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let nbwitnesses = Options.get_z3_witnesses () in
let buf : ref string = alloc "" in
let prog = process_files_for_z3 (fun s -> buf := !buf ^ s) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
with_z3_thread_or batch out_dir (Options.get_debug ()) (Options.get_save_z3_transcript ()) (fun z3 ->
z3.to_z3 !buf;
do_test (if batch then Some (OS.concat out_dir "testcases.c") else None) nbwitnesses prog z3
)
let produce_z3_and_test
(batch: bool)
(out_dir: string)
(name: string)
: Tot process_files_t
= produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_test out_dir out_file z3 prog name nbwitnesses (Options.get_z3_branch_depth ()) (Options.get_z3_pos_test ()) (Options.get_z3_neg_test ())
) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | batch: Prims.bool -> out_dir: Prims.string -> names: (Prims.string * Prims.string)
-> Main.process_files_t | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.string",
"FStar.Pervasives.Native.tuple2",
"Main.produce_z3_and_test_gen",
"FStar.Pervasives.Native.option",
"Prims.int",
"Z3TestGen.prog",
"Z3.Base.z3",
"Z3TestGen.do_diff_test",
"Prims.unit",
"Prims.nat",
"Options.get_z3_branch_depth",
"Main.process_files_t"
] | [] | false | false | false | true | false | let produce_z3_and_diff_test (batch: bool) (out_dir: string) (names: (string & string))
: Tot process_files_t =
| let name1, name2 = names in
produce_z3_and_test_gen batch
out_dir
(fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_diff_test out_dir
out_file
z3
prog
name1
name2
nbwitnesses
(Options.get_z3_branch_depth ())) | false |
Lib.IntTypes.fst | Lib.IntTypes.logxor_lemma | val logxor_lemma: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(a `logxor` (a `logxor` b) == b /\
a `logxor` (b `logxor` a) == b /\
a `logxor` (mk_int #t #l 0) == a) | val logxor_lemma: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(a `logxor` (a `logxor` b) == b /\
a `logxor` (b `logxor` a) == b /\
a `logxor` (mk_int #t #l 0) == a) | let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 467,
"start_col": 0,
"start_line": 453
} | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"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": 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": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.logxor a (Lib.IntTypes.logxor a b) == b /\
Lib.IntTypes.logxor a (Lib.IntTypes.logxor b a) == b /\
Lib.IntTypes.logxor a (Lib.IntTypes.mk_int 0) == a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.v_extensionality",
"Lib.IntTypes.logxor",
"Lib.IntTypes.mk_int",
"Prims.unit",
"FStar.UInt.logxor_lemma_1",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"FStar.Int.logxor_lemma_1",
"FStar.UInt.logxor_commutative",
"FStar.Int.logxor_commutative",
"Lib.IntTypes.logxor_lemma_"
] | [] | false | false | true | false | false | let logxor_lemma #t #l a b =
| logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
(match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b));
v_extensionality (logxor a (logxor b a)) b;
(match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a));
v_extensionality (logxor a (mk_int #t #l 0)) a | false |
FStar.Int.fst | FStar.Int.one_to_vec_lemma | val one_to_vec_lemma: #n:pos{1 < n} -> 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{1 < n} -> 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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 88,
"start_col": 0,
"start_line": 87
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.to_vec (FStar.Int.one n)) i =
FStar.Seq.Base.index (FStar.BitVector.elem_vec (n - 1)) i)
[SMTPat (FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.one n)) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.bool",
"FStar.Int.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 |
FStar.Int.fst | FStar.Int.from_vec_lemma_2 | val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires from_vec a = from_vec b) (ensures equal a b) | val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires from_vec a = from_vec b) (ensures equal a b) | let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 80,
"start_col": 0,
"start_line": 80
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.from_vec a = FStar.Int.from_vec b)
(ensures FStar.Seq.Base.equal a b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.BitVector.bv_t",
"FStar.Int.inverse_vec_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let from_vec_lemma_2 #n a b =
| inverse_vec_lemma a;
inverse_vec_lemma b | false |
FStar.Int.fst | FStar.Int.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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 103,
"start_col": 0,
"start_line": 102
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.from_vec FStar.BitVector.ones_vec = FStar.Int.ones n)
[SMTPat (FStar.Int.from_vec FStar.BitVector.ones_vec)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.to_vec_lemma_2",
"FStar.Int.from_vec",
"FStar.BitVector.ones_vec",
"FStar.Int.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.Int.fst | FStar.Int.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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 77,
"end_line": 85,
"start_col": 0,
"start_line": 85
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.from_vec FStar.BitVector.zero_vec = FStar.Int.zero n)
[SMTPat (FStar.Int.from_vec FStar.BitVector.zero_vec)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.to_vec_lemma_2",
"FStar.Int.from_vec",
"FStar.BitVector.zero_vec",
"FStar.Int.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 |
Main.fst | Main.go | val go: Prims.unit -> ML unit | val go: Prims.unit -> ML unit | let go () : ML unit =
(* Parse command-line options. This action is only accumulating values into globals, without any further action (other than --help and --version, which interrupt the execution.) *)
let cmd_line_files = Options.parse_cmd_line() in
let cfg_opt = Deps.get_config () in
(* Special mode: --check_inplace_hashes *)
let inplace_hashes = Options.get_check_inplace_hashes () in
if Cons? inplace_hashes
then Batch.check_inplace_hashes inplace_hashes
else
let micro_step = Options.get_micro_step () in
if micro_step = Some HashingOptions.MicroStepEmitConfig
then (
emit_config_as_fstar_module ();
exit 0
)
else
if micro_step = Some HashingOptions.MicroStepCopyClangFormat
then
(* Special mode: --__micro_step copy_clang_format *)
let _ = Batch.copy_clang_format (Options.get_output_dir ()) in
exit 0
else
if micro_step = Some HashingOptions.MicroStepCopyEverParseH
then
(* Special mode: --__micro_step copy_everparse_h *)
let _ = Batch.copy_everparse_h
(Options.get_clang_format ())
(Options.get_clang_format_executable ())
(Options.get_input_stream_binding ())
(Options.get_output_dir ())
in
exit 0
else
(* for other modes, a nonempty list of files is needed on the command line, so if none are there, then we shall print the help message *)
let input_stream_binding = Options.get_input_stream_binding () in
if Nil? cmd_line_files
then let _ = Options.display_usage () in exit 1
else
let out_dir = Options.get_output_dir () in
(* Special mode: --__micro_step *)
match micro_step with
| Some step ->
let f = match step with
| HashingOptions.MicroStepExtract -> Batch.extract_fst_file
| HashingOptions.MicroStepVerify -> Batch.verify_fst_file
in
List.iter (f input_stream_binding out_dir) cmd_line_files
| None ->
(* Special mode: --makefile" *)
match Options.get_makefile () with
| Some t ->
GenMakefile.write_makefile
t
input_stream_binding
(not (Options.get_no_everparse_h ()))
(Options.get_emit_output_types_defs ())
(Options.get_skip_o_rules ())
(Options.get_clang_format ())
cmd_line_files
| None ->
(* Special mode: --__produce_c_from_existing_krml *)
if Options.get_produce_c_from_existing_krml ()
then
let _ = List.iter
(produce_and_postprocess_c out_dir)
cmd_line_files
in
FStar.IO.print_string "EverParse succeeded!\n"
else
(* for other modes, the list of files provided on the command line is assumed to be a list of .3d files, and the list of all .3d files in dependency order has to be inferred from the list of .3d input files provided by the user, unless --__skip_deps is provided *)
let all_files =
if Options.get_skip_deps ()
then List.Tot.rev cmd_line_files (* files are accumulated in reverse on the command line *)
else Deps.collect_and_sort_dependencies cmd_line_files
in
let all_files_and_modules = List.map (fun file -> (file, Options.get_module_name file)) all_files in
(* Special mode: --check_hashes *)
let check_hashes = Options.get_check_hashes () in
if Some? check_hashes
then Batch.check_all_hashes (Some?.v check_hashes) out_dir all_files_and_modules
else
(* Special mode: --emit_smt_encoding *)
if Options.get_emit_smt_encoding ()
then produce_z3 all_files_and_modules
else
(* Default mode: process .3d files *)
let batch = Options.get_batch () in
let should_emit_fstar_code : string -> ML bool =
let cmd_line_modules = List.map Options.get_module_name cmd_line_files in
fun modul ->
batch || List.Tot.mem modul cmd_line_modules in
let process : process_files_t =
(* Special mode: --test_checker *)
let test_checker = Options.get_test_checker () in
if Some? test_checker
then produce_test_checker_exe batch out_dir (Some?.v test_checker)
else
(* Special mode: --z3_diff_test *)
let z3_diff_test = Options.get_z3_diff_test () in
if Some? z3_diff_test
then produce_z3_and_diff_test batch out_dir (Some?.v z3_diff_test)
else
(* Special mode: --z3_test *)
let z3_test = Options.get_z3_test () in
if Some? z3_test
then produce_z3_and_test batch out_dir (Some?.v z3_test)
else process_files
in
match process all_files_and_modules should_emit_fstar_code (Options.get_emit_output_types_defs ()) with
| None -> ()
| Some finalize ->
(* we need to pretty-print source modules in all cases, regardless of --batch,
because of the Makefile scenario
*)
(*
* pretty print only the modules we emitted code for
*)
Batch.pretty_print_source_modules input_stream_binding out_dir
(List.filter (fun (_, m) -> should_emit_fstar_code m) all_files_and_modules);
(* Sub-mode of the default mode: --batch *)
let _ =
if batch
then
let _ = Batch.postprocess_fst
input_stream_binding
(Options.get_emit_output_types_defs ())
(Options.get_add_include ())
(Options.get_clang_format ())
(Options.get_clang_format_executable ())
(Options.get_skip_c_makefiles ())
(Options.get_cleanup ())
(Options.get_no_everparse_h ())
(Options.get_save_hashes ())
out_dir all_files_and_modules
in
FStar.IO.print_string "EverParse succeeded!\n"
else
(* If --batch is not set, then we also need to postprocess the wrappers and assertions
(copyright header and clang-format) *)
Batch.postprocess_wrappers
input_stream_binding
(Options.get_clang_format ())
(Options.get_clang_format_executable ())
out_dir all_files_and_modules
in
finalize () | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 727,
"start_col": 0,
"start_line": 582
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false)
let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end
let build_and_run_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []
end
let with_z3_thread_or
(batch: bool)
(out_dir: string)
(debug: bool)
(transcript: option string)
(f: (Z3.z3 -> ML unit))
: ML (option (unit -> ML unit))
= if batch
then
let thr = Z3.with_z3_thread debug transcript f in
Some (fun _ ->
Z3.wait_for_z3_thread thr;
build_and_run_test_exe out_dir
)
else begin
Z3.with_z3 debug transcript f;
None
end
let produce_z3_and_test_gen
(batch: bool)
(out_dir: string)
(do_test: option string -> int -> Z3TestGen.prog -> Z3.z3 -> ML unit)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let nbwitnesses = Options.get_z3_witnesses () in
let buf : ref string = alloc "" in
let prog = process_files_for_z3 (fun s -> buf := !buf ^ s) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
with_z3_thread_or batch out_dir (Options.get_debug ()) (Options.get_save_z3_transcript ()) (fun z3 ->
z3.to_z3 !buf;
do_test (if batch then Some (OS.concat out_dir "testcases.c") else None) nbwitnesses prog z3
)
let produce_z3_and_test
(batch: bool)
(out_dir: string)
(name: string)
: Tot process_files_t
= produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_test out_dir out_file z3 prog name nbwitnesses (Options.get_z3_branch_depth ()) (Options.get_z3_pos_test ()) (Options.get_z3_neg_test ())
)
let produce_z3_and_diff_test
(batch: bool)
(out_dir: string)
(names: (string & string))
: Tot process_files_t
=
let (name1, name2) = names in
produce_z3_and_test_gen batch out_dir (fun out_file nbwitnesses prog z3 ->
Z3TestGen.do_diff_test out_dir out_file z3 prog name1 name2 nbwitnesses (Options.get_z3_branch_depth ())
)
let produce_test_checker_exe
(batch: bool)
(out_dir: string)
(name1: string)
: Tot process_files_t
= fun
(files_and_modules:list (string & string))
(emit_fstar:string -> ML bool)
(emit_output_types_defs:bool)
->
let prog = process_files_for_z3 (fun _ -> ()) files_and_modules (if batch then Some emit_fstar else None) emit_output_types_defs in
Z3TestGen.produce_test_checker_exe (OS.concat out_dir "testcases.c") prog name1;
Some (fun _ ->
if batch then
build_test_exe out_dir
)
let produce_and_postprocess_c
(out_dir: string)
(file: string)
: ML unit
=
let modul = Options.get_module_name file in
let deps = Deps.collect_and_sort_dependencies [file] in
let dep_files_and_modules = List.map (fun f -> (f, Options.get_module_name f)) deps in
(* remove the current module from the deps *)
let dep_files_and_modules = List.filter (fun (_, m) -> m <> modul) dep_files_and_modules in
Batch.produce_and_postprocess_one_c
(Options.get_input_stream_binding ())
(Options.get_emit_output_types_defs ())
(Options.get_add_include ())
(Options.get_clang_format ())
(Options.get_clang_format_executable ())
out_dir
file
modul
dep_files_and_modules | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Prims.uu___is_Cons",
"Prims.string",
"Batch.check_inplace_hashes",
"Prims.bool",
"Prims.op_Equality",
"FStar.Pervasives.Native.option",
"HashingOptions.micro_step_t",
"FStar.Pervasives.Native.Some",
"HashingOptions.MicroStepEmitConfig",
"FStar.All.exit",
"Main.emit_config_as_fstar_module",
"HashingOptions.MicroStepCopyClangFormat",
"Batch.copy_clang_format",
"Options.get_output_dir",
"HashingOptions.MicroStepCopyEverParseH",
"Batch.copy_everparse_h",
"HashingOptions.input_stream_binding_t",
"Options.get_input_stream_binding",
"Options.get_clang_format_executable",
"Options.get_clang_format",
"Prims.uu___is_Nil",
"Options.display_usage",
"FStar.List.iter",
"Batch.extract_fst_file",
"Batch.verify_fst_file",
"HashingOptions.makefile_type",
"GenMakefile.write_makefile",
"Options.get_skip_o_rules",
"Options.get_emit_output_types_defs",
"Prims.op_Negation",
"Options.get_no_everparse_h",
"FStar.IO.print_string",
"Main.produce_and_postprocess_c",
"FStar.Pervasives.Native.uu___is_Some",
"HashingOptions.check_hashes_t",
"Batch.check_all_hashes",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Main.produce_z3",
"Batch.postprocess_fst",
"Options.get_save_hashes",
"Options.get_cleanup",
"Options.get_skip_c_makefiles",
"Prims.list",
"Options.get_add_include",
"Batch.postprocess_wrappers",
"Batch.pretty_print_source_modules",
"FStar.Pervasives.Native.tuple2",
"FStar.List.filter",
"Main.process_files_t",
"Main.produce_test_checker_exe",
"Main.produce_z3_and_diff_test",
"Main.produce_z3_and_test",
"Main.process_files",
"Options.get_z3_test",
"Options.get_z3_diff_test",
"Options.get_test_checker",
"Prims.op_BarBar",
"FStar.List.Tot.Base.mem",
"FStar.List.map",
"Options.get_module_name",
"Options.get_batch",
"Options.get_emit_smt_encoding",
"Options.get_check_hashes",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"Deps.collect_and_sort_dependencies",
"Options.get_skip_deps",
"Options.get_produce_c_from_existing_krml",
"Options.get_makefile",
"Options.get_micro_step",
"Options.get_check_inplace_hashes",
"Config.config",
"Deps.get_config",
"Options.parse_cmd_line"
] | [] | false | true | false | false | false | let go () : ML unit =
| let cmd_line_files = Options.parse_cmd_line () in
let cfg_opt = Deps.get_config () in
let inplace_hashes = Options.get_check_inplace_hashes () in
if Cons? inplace_hashes
then Batch.check_inplace_hashes inplace_hashes
else
let micro_step = Options.get_micro_step () in
if micro_step = Some HashingOptions.MicroStepEmitConfig
then
(emit_config_as_fstar_module ();
exit 0)
else
if micro_step = Some HashingOptions.MicroStepCopyClangFormat
then
let _ = Batch.copy_clang_format (Options.get_output_dir ()) in
exit 0
else
if micro_step = Some HashingOptions.MicroStepCopyEverParseH
then
let _ =
Batch.copy_everparse_h (Options.get_clang_format ())
(Options.get_clang_format_executable ())
(Options.get_input_stream_binding ())
(Options.get_output_dir ())
in
exit 0
else
let input_stream_binding = Options.get_input_stream_binding () in
if Nil? cmd_line_files
then
let _ = Options.display_usage () in
exit 1
else
let out_dir = Options.get_output_dir () in
match micro_step with
| Some step ->
let f =
match step with
| HashingOptions.MicroStepExtract -> Batch.extract_fst_file
| HashingOptions.MicroStepVerify -> Batch.verify_fst_file
in
List.iter (f input_stream_binding out_dir) cmd_line_files
| None ->
match Options.get_makefile () with
| Some t ->
GenMakefile.write_makefile t
input_stream_binding
(not (Options.get_no_everparse_h ()))
(Options.get_emit_output_types_defs ())
(Options.get_skip_o_rules ())
(Options.get_clang_format ())
cmd_line_files
| None ->
if Options.get_produce_c_from_existing_krml ()
then
let _ = List.iter (produce_and_postprocess_c out_dir) cmd_line_files in
FStar.IO.print_string "EverParse succeeded!\n"
else
let all_files =
if Options.get_skip_deps ()
then List.Tot.rev cmd_line_files
else Deps.collect_and_sort_dependencies cmd_line_files
in
let all_files_and_modules =
List.map (fun file -> (file, Options.get_module_name file)) all_files
in
let check_hashes = Options.get_check_hashes () in
if Some? check_hashes
then Batch.check_all_hashes (Some?.v check_hashes) out_dir all_files_and_modules
else
if Options.get_emit_smt_encoding ()
then produce_z3 all_files_and_modules
else
let batch = Options.get_batch () in
let should_emit_fstar_code: string -> ML bool =
let cmd_line_modules = List.map Options.get_module_name cmd_line_files in
fun modul -> batch || List.Tot.mem modul cmd_line_modules
in
let process:process_files_t =
let test_checker = Options.get_test_checker () in
if Some? test_checker
then produce_test_checker_exe batch out_dir (Some?.v test_checker)
else
let z3_diff_test = Options.get_z3_diff_test () in
if Some? z3_diff_test
then produce_z3_and_diff_test batch out_dir (Some?.v z3_diff_test)
else
let z3_test = Options.get_z3_test () in
if Some? z3_test
then produce_z3_and_test batch out_dir (Some?.v z3_test)
else process_files
in
match
process all_files_and_modules
should_emit_fstar_code
(Options.get_emit_output_types_defs ())
with
| None -> ()
| Some finalize ->
Batch.pretty_print_source_modules input_stream_binding
out_dir
(List.filter (fun (_, m) -> should_emit_fstar_code m) all_files_and_modules);
let _ =
if batch
then
let _ =
Batch.postprocess_fst input_stream_binding
(Options.get_emit_output_types_defs ()) (Options.get_add_include ())
(Options.get_clang_format ()) (Options.get_clang_format_executable ())
(Options.get_skip_c_makefiles ()) (Options.get_cleanup ())
(Options.get_no_everparse_h ()) (Options.get_save_hashes ()) out_dir
all_files_and_modules
in
FStar.IO.print_string "EverParse succeeded!\n"
else
Batch.postprocess_wrappers input_stream_binding
(Options.get_clang_format ())
(Options.get_clang_format_executable ())
out_dir
all_files_and_modules
in
finalize () | false |
FStar.Int.fst | FStar.Int.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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 83,
"start_col": 0,
"start_line": 82
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.to_vec (FStar.Int.zero n)) i =
FStar.Seq.Base.index FStar.BitVector.zero_vec i)
[SMTPat (FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.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.Int.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.Int.fst | FStar.Int.pow2_from_vec_lemma | val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} ->
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:pos{p < n-1} ->
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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 67,
"end_line": 98,
"start_col": 0,
"start_line": 97
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.pos{p < n - 1}
-> FStar.Pervasives.Lemma
(ensures FStar.Int.from_vec (FStar.BitVector.elem_vec p) = FStar.Int.pow2_n (n - p - 1))
[SMTPat (FStar.Int.from_vec (FStar.BitVector.elem_vec p))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"FStar.Int.to_vec_lemma_2",
"FStar.Int.from_vec",
"FStar.BitVector.elem_vec",
"FStar.Int.pow2_n",
"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.Int.fst | FStar.Int.nth_lemma | val nth_lemma: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires forall (i:nat{i < n}). nth a i = nth b i)
(ensures a = b) | val nth_lemma: #n:pos -> a:int_t n -> b:int_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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 107,
"start_col": 0,
"start_line": 105
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma
(requires forall (i: Prims.nat{i < n}). FStar.Int.nth a i = FStar.Int.nth b i) (ensures a = b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.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.Int.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.Int.fst | FStar.Int.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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 71,
"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 FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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 | 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.Int.to_vec (FStar.Int.from_vec vec)) i)
[SMTPat (FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.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.Int.from_vec",
"FStar.Seq.Base.index",
"Prims.bool",
"FStar.Int.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.Int.fst | FStar.Int.pow2_to_vec_lemma | val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> 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-1} -> 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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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": true,
"smtencoding_l_arith_repr": "native",
"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 - 1} -> i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.pow2_n p)) i =
FStar.Seq.Base.index (FStar.BitVector.elem_vec (n - p - 1)) i)
[SMTPat (FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.pow2_n p)) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Int.one_to_vec_lemma",
"FStar.Int.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.Int.fst | FStar.Int.logand_associative | val logand_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n ->
Lemma (logand #n (logand #n a b) c = logand #n a (logand #n b c)) | val logand_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n ->
Lemma (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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 126,
"start_col": 0,
"start_line": 125
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> b: FStar.Int.int_t n -> c: FStar.Int.int_t n
-> FStar.Pervasives.Lemma
(ensures FStar.Int.logand (FStar.Int.logand a b) c = FStar.Int.logand a (FStar.Int.logand b c)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.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.Int.fst | FStar.Int.logand_self | val logand_self: #n:pos -> a:int_t n ->
Lemma (logand #n a a = a) | val logand_self: #n:pos -> a:int_t n ->
Lemma (logand #n a a = a) | let logand_self #n a = nth_lemma #n (logand #n a a) a | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 128,
"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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.logand a a = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"Prims.unit"
] | [] | true | false | true | false | false | let logand_self #n a =
| nth_lemma #n (logand #n a a) a | false |
FStar.Int.fst | FStar.Int.logand_commutative | val logand_commutative: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires True) (ensures (logand #n a b = logand #n b a)) | val logand_commutative: #n:pos -> a:int_t n -> b:int_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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 76,
"end_line": 123,
"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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.logand a b = FStar.Int.logand b a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.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.Int.fst | FStar.Int.logand_lemma_1 | val logand_lemma_1: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) | val logand_lemma_1: #n:pos -> a:int_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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 46,
"end_line": 131,
"start_col": 0,
"start_line": 130
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.logand a (FStar.Int.zero n) = FStar.Int.zero n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"FStar.Int.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.Int.fst | FStar.Int.logand_pos_le | val logand_pos_le: #n:pos{1 < n} -> a:int_t n{0 <= a} -> b:int_t n{0 <= b} ->
Lemma (0 <= logand a b /\ logand a b <= a /\ logand a b <= b) | val logand_pos_le: #n:pos{1 < n} -> a:int_t n{0 <= a} -> b:int_t n{0 <= b} ->
Lemma (0 <= logand a b /\ logand a b <= a /\ logand a b <= b) | let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b) | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 143,
"start_col": 0,
"start_line": 142
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n {0 <= a} -> b: FStar.Int.int_t n {0 <= b}
-> FStar.Pervasives.Lemma
(ensures 0 <= FStar.Int.logand a b /\ FStar.Int.logand a b <= a /\ FStar.Int.logand a b <= b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"Prims.op_LessThanOrEqual",
"FStar.UInt.logand_le",
"FStar.Int.to_uint",
"Prims.unit"
] | [] | true | false | true | false | false | let logand_pos_le #n a b =
| UInt.logand_le (to_uint a) (to_uint b) | false |
FStar.Int.fst | FStar.Int.logand_lemma_2 | val logand_lemma_2: #n:pos -> a:int_t n ->
Lemma (logand #n a (ones n) = a) | val logand_lemma_2: #n:pos -> a:int_t n ->
Lemma (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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.logand a (FStar.Int.ones n) = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"FStar.Int.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.Int.fst | FStar.Int.logxor_self | val logxor_self: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a a = zero n)) | val logxor_self: #n:pos -> a:int_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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 159,
"start_col": 0,
"start_line": 159
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.logxor a a = FStar.Int.zero n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logxor",
"FStar.Int.zero",
"Prims.unit"
] | [] | true | false | true | false | false | let logxor_self #n a =
| nth_lemma #n (logxor #n a a) (zero n) | false |
FStar.Int.fst | FStar.Int.logand_pow2_minus_one | val logand_pow2_minus_one: #n:pos{1 < n} -> a:int_t n -> m:pos{m < n} ->
Lemma (0 <= logand a (pow2_minus_one m) /\
logand a (pow2_minus_one m) <= pow2_minus_one #n m) | val logand_pow2_minus_one: #n:pos{1 < n} -> a:int_t n -> m:pos{m < n} ->
Lemma (0 <= logand a (pow2_minus_one m) /\
logand a (pow2_minus_one m) <= pow2_minus_one #n m) | let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m)) | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 146,
"start_col": 0,
"start_line": 145
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> m: Prims.pos{m < n}
-> FStar.Pervasives.Lemma
(ensures
0 <= FStar.Int.logand a (FStar.Int.pow2_minus_one m) /\
FStar.Int.logand a (FStar.Int.pow2_minus_one m) <= FStar.Int.pow2_minus_one m) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"FStar.UInt.logand_le",
"FStar.Int.to_uint",
"FStar.Int.pow2_minus_one",
"Prims.unit"
] | [] | true | false | true | false | false | let logand_pow2_minus_one #n a m =
| UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m)) | false |
FStar.Int.fst | FStar.Int.logxor_associative | val logxor_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_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:int_t n -> b:int_t n -> c:int_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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 106,
"end_line": 157,
"start_col": 0,
"start_line": 157
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> b: FStar.Int.int_t n -> c: FStar.Int.int_t n
-> FStar.Pervasives.Lemma
(ensures FStar.Int.logxor (FStar.Int.logxor a b) c = FStar.Int.logxor a (FStar.Int.logxor b c)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.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.Int.fst | FStar.Int.logxor_inv | val logxor_inv: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a = logxor #n (logxor #n a b) b) | val logxor_inv: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a = logxor #n (logxor #n a b) b) | let logxor_inv #n a b =
UInt.logxor_inv (to_uint a) (to_uint b) | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 166,
"start_col": 0,
"start_line": 165
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
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) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures a = FStar.Int.logxor (FStar.Int.logxor a b) b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.UInt.logxor_inv",
"FStar.Int.to_uint",
"Prims.unit"
] | [] | true | false | true | false | false | let logxor_inv #n a b =
| UInt.logxor_inv (to_uint a) (to_uint b) | false |
FStar.Int.fst | FStar.Int.sign_bit_positive | val sign_bit_positive: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = false <==> 0 <= a) | val sign_bit_positive: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = false <==> 0 <= a) | let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 140,
"start_col": 0,
"start_line": 139
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.nth a 0 = false <==> 0 <= a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"FStar.UInt.from_vec_propriety",
"FStar.Int.to_vec",
"Prims.unit"
] | [] | true | false | true | false | false | let sign_bit_positive #n a =
| UInt.from_vec_propriety #n (to_vec a) 1 | false |
FStar.Int.fst | FStar.Int.sign_bit_negative | val sign_bit_negative: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = true <==> a < 0) | val sign_bit_negative: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = true <==> a < 0) | let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 137,
"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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.nth a 0 = true <==> a < 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"FStar.UInt.from_vec_propriety",
"FStar.Int.to_vec",
"Prims.unit"
] | [] | true | false | true | false | false | let sign_bit_negative #n a =
| UInt.from_vec_propriety #n (to_vec a) 1 | false |
FStar.Int.fst | FStar.Int.logxor_commutative | val logxor_commutative: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) | val logxor_commutative: #n:pos -> a:int_t n -> b:int_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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 76,
"end_line": 155,
"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 FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.logxor a b = FStar.Int.logxor b a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.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.Int.fst | FStar.Int.lognot_negative | val lognot_negative: #n:pos -> a:int_t n -> Lemma
(requires a < 0)
(ensures lognot a == UInt.lognot #n (a + pow2 n)) | val lognot_negative: #n:pos -> a:int_t n -> Lemma
(requires a < 0)
(ensures lognot a == UInt.lognot #n (a + pow2 n)) | let lognot_negative #n a =
assert_norm (pow2 n = 2 * pow2 (n - 1));
UInt.lemma_lognot_value_mod #n (a + pow2 n) | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 173,
"start_col": 0,
"start_line": 171
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
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 logxor_inv #n a b =
UInt.logxor_inv (to_uint a) (to_uint b)
let logxor_neq_nonzero #n a b =
UInt.logxor_neq_nonzero (to_uint a) (to_uint b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n
-> FStar.Pervasives.Lemma (requires a < 0)
(ensures FStar.Int.lognot a == FStar.UInt.lognot (a + Prims.pow2 n)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.UInt.lemma_lognot_value_mod",
"Prims.op_Addition",
"Prims.pow2",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_Subtraction"
] | [] | true | false | true | false | false | let lognot_negative #n a =
| assert_norm (pow2 n = 2 * pow2 (n - 1));
UInt.lemma_lognot_value_mod #n (a + pow2 n) | false |
FStar.Int.fst | FStar.Int.logxor_lemma_1 | val logxor_lemma_1: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a (zero n) = a)) | val logxor_lemma_1: #n:pos -> a:int_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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 161,
"start_col": 0,
"start_line": 161
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.logxor a (FStar.Int.zero n) = a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logxor",
"FStar.Int.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.Int.fst | FStar.Int.logxor_lemma_2 | val logxor_lemma_2: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a)) | val logxor_lemma_2: #n:pos -> a:int_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.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 163,
"start_col": 0,
"start_line": 163
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
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.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.logxor a (FStar.Int.ones n) = FStar.Int.lognot a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logxor",
"FStar.Int.ones",
"FStar.Int.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 |
FStar.Int.fst | FStar.Int.logxor_neq_nonzero | val logxor_neq_nonzero: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a <> b ==> logxor a b <> 0) | val logxor_neq_nonzero: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a <> b ==> logxor a b <> 0) | let logxor_neq_nonzero #n a b =
UInt.logxor_neq_nonzero (to_uint a) (to_uint b) | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 49,
"end_line": 169,
"start_col": 0,
"start_line": 168
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
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 logxor_inv #n a b =
UInt.logxor_inv (to_uint a) (to_uint b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures a <> b ==> FStar.Int.logxor a b <> 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.UInt.logxor_neq_nonzero",
"FStar.Int.to_uint",
"Prims.unit"
] | [] | true | false | true | false | false | let logxor_neq_nonzero #n a b =
| UInt.logxor_neq_nonzero (to_uint a) (to_uint b) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.cur_formula | val cur_formula: Prims.unit -> Tac formula | val cur_formula: Prims.unit -> Tac formula | let cur_formula () : Tac formula = term_as_formula (cur_goal ()) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 64,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.V2.Formula.formula | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Reflection.V2.Formula.term_as_formula",
"FStar.Reflection.V2.Formula.formula",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.cur_goal",
"FStar.Stubs.Reflection.Types.typ"
] | [] | false | true | false | false | false | let cur_formula () : Tac formula =
| term_as_formula (cur_goal ()) | false |
FStar.Int.fst | FStar.Int.shift_left_value_lemma | val shift_left_value_lemma: #n:pos -> a:int_t n{0 <= a} -> 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:int_t n{0 <= a} -> 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 =
UInt.shift_left_value_lemma #n a s | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 180,
"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 FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
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 logxor_inv #n a b =
UInt.logxor_inv (to_uint a) (to_uint b)
let logxor_neq_nonzero #n a b =
UInt.logxor_neq_nonzero (to_uint a) (to_uint b)
let lognot_negative #n a =
assert_norm (pow2 n = 2 * pow2 (n - 1));
UInt.lemma_lognot_value_mod #n (a + pow2 n)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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.Int.int_t n {0 <= a} -> s: Prims.nat
-> FStar.Pervasives.Lemma (ensures FStar.Int.shift_left a s = a * Prims.pow2 s @% Prims.pow2 n)
[SMTPat (FStar.Int.shift_left a s)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.nat",
"FStar.UInt.shift_left_value_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let shift_left_value_lemma #n a s =
| UInt.shift_left_value_lemma #n a s | false |
Pulse.Checker.AssertWithBinders.fst | Pulse.Checker.AssertWithBinders.option_must | val option_must (f: option 'a) (msg: string) : T.Tac 'a | val option_must (f: option 'a) (msg: string) : T.Tac 'a | let option_must (f:option 'a) (msg:string) : T.Tac 'a =
match f with
| Some x -> x
| None -> T.fail msg | {
"file_name": "lib/steel/pulse/Pulse.Checker.AssertWithBinders.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 44,
"start_col": 0,
"start_line": 41
} | (*
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.AssertWithBinders
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Elaborate.Pure
open Pulse.Typing.Env
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module PC = Pulse.Checker.Pure
module P = Pulse.Syntax.Printer
module N = Pulse.Syntax.Naming
module PS = Pulse.Checker.Prover.Substs
module Prover = Pulse.Checker.Prover
module Env = Pulse.Typing.Env
open Pulse.Show
module RU = Pulse.RuntimeUtils
let is_host_term (t:R.term) = not (R.Tv_Unknown? (R.inspect_ln t))
let debug_log = Pulse.Typing.debug_log "with_binders" | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Show.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.AssertWithBinders.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Show",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover",
"short_module": "Prover"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Naming",
"short_module": "N"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Pure",
"short_module": "PC"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"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": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"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 | f: FStar.Pervasives.Native.option 'a -> msg: Prims.string -> FStar.Tactics.Effect.Tac 'a | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Pervasives.Native.option",
"Prims.string",
"FStar.Tactics.V2.Derived.fail"
] | [] | false | true | false | false | false | let option_must (f: option 'a) (msg: string) : T.Tac 'a =
| match f with
| Some x -> x
| None -> T.fail msg | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.l_revert | val l_revert: Prims.unit -> Tac unit | val l_revert: Prims.unit -> Tac unit | let l_revert () : Tac unit =
revert ();
apply (`revert_squash) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 38,
"start_col": 0,
"start_line": 36
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply",
"FStar.Stubs.Tactics.V2.Builtins.revert"
] | [] | false | true | false | false | false | let l_revert () : Tac unit =
| revert ();
apply (`revert_squash) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.fa_intro_lem | val fa_intro_lem (#a: Type) (#p: (a -> Type)) (f: (x: a -> squash (p x)))
: Lemma (forall (x: a). p x) | val fa_intro_lem (#a: Type) (#p: (a -> Type)) (f: (x: a -> squash (p x)))
: Lemma (forall (x: a). p x) | let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x))) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 85,
"end_line": 48,
"start_col": 8,
"start_line": 46
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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: (x: a -> Prims.squash (p x)) -> FStar.Pervasives.Lemma (ensures forall (x: a). p x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.squash",
"FStar.Classical.lemma_forall_intro_gtot",
"FStar.IndefiniteDescription.elim_squash",
"Prims.unit",
"Prims.l_True",
"Prims.l_Forall",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let fa_intro_lem (#a: Type) (#p: (a -> Type)) (f: (x: a -> squash (p x)))
: Lemma (forall (x: a). p x) =
| FStar.Classical.lemma_forall_intro_gtot ((fun x -> FStar.IndefiniteDescription.elim_squash (f x))
<:
(x: a -> GTot (p x))) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.forall_intro | val forall_intro: Prims.unit -> Tac binding | val forall_intro: Prims.unit -> Tac binding | let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro () | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 53,
"start_col": 0,
"start_line": 51
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Stubs.Tactics.V2.Builtins.intro",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Tactics.V2.Derived.apply_lemma",
"FStar.Tactics.NamedView.binding"
] | [] | false | true | false | false | false | let forall_intro () : Tac binding =
| apply_lemma (`fa_intro_lem);
intro () | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.split | val split: Prims.unit -> Tac unit | val split: Prims.unit -> Tac unit | let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal" | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 70,
"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 FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.try_with",
"FStar.Tactics.V2.Derived.apply_lemma",
"Prims.exn",
"FStar.Tactics.V2.Derived.fail"
] | [] | false | true | false | false | false | let split () : Tac unit =
| try apply_lemma (`split_lem) with | _ -> fail "Could not split goal" | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.forall_intros | val forall_intros: Prims.unit -> Tac (list binding) | val forall_intros: Prims.unit -> Tac (list binding) | let forall_intros () : Tac (list binding) = repeat1 forall_intro | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 64,
"end_line": 61,
"start_col": 0,
"start_line": 61
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.repeat1",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.forall_intro",
"Prims.list"
] | [] | false | true | false | false | false | let forall_intros () : Tac (list binding) =
| repeat1 forall_intro | false |
FStar.Int.fst | FStar.Int.logand_max | val logand_max: #n:pos{1 < n} -> a:int_t n{0 <= a} ->
Lemma (0 <= logand a (max_int n) /\ a = logand a (max_int n)) | val logand_max: #n:pos{1 < n} -> a:int_t n{0 <= a} ->
Lemma (0 <= logand a (max_int n) /\ a = logand a (max_int n)) | let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n)) | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 152,
"start_col": 0,
"start_line": 149
} | (*
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.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.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)
| _ -> ()
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
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
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
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n 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
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
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
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
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n 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 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 sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.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.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.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": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Int.int_t n {0 <= a}
-> FStar.Pervasives.Lemma
(ensures
0 <= FStar.Int.logand a (FStar.Int.max_int n) /\ a = FStar.Int.logand a (FStar.Int.max_int n)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"Prims.op_LessThanOrEqual",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"FStar.Int.max_int",
"Prims.unit",
"FStar.Int.sign_bit_positive"
] | [] | true | false | true | false | false | let logand_max #n a =
| sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n)) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.implies_intro | val implies_intro: Prims.unit -> Tac binding | val implies_intro: Prims.unit -> Tac binding | let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro () | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 81,
"start_col": 0,
"start_line": 79
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Stubs.Tactics.V2.Builtins.intro",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Tactics.V2.Derived.apply_lemma",
"FStar.Tactics.NamedView.binding"
] | [] | false | true | false | false | false | let implies_intro () : Tac binding =
| apply_lemma (`imp_intro_lem);
intro () | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.implies_intro_as | val implies_intro_as (s: string) : Tac binding | val implies_intro_as (s: string) : Tac binding | let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 14,
"end_line": 85,
"start_col": 0,
"start_line": 83
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.string",
"FStar.Tactics.V2.Derived.intro_as",
"FStar.Tactics.NamedView.binding",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | false | true | false | false | false | let implies_intro_as (s: string) : Tac binding =
| apply_lemma (`imp_intro_lem);
intro_as s | false |
Pulse.Checker.AssertWithBinders.fst | Pulse.Checker.AssertWithBinders.closing | val closing (bs: list (ppname & var & typ)) : subst | val closing (bs: list (ppname & var & typ)) : subst | let closing (bs:list (ppname & var & typ)) : subst =
L.fold_right (fun (_, x, _) (n, ss) ->
n+1,
(ND x n)::ss
) bs (0, []) |> snd | {
"file_name": "lib/steel/pulse/Pulse.Checker.AssertWithBinders.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 112,
"start_col": 0,
"start_line": 108
} | (*
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.AssertWithBinders
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Elaborate.Pure
open Pulse.Typing.Env
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module PC = Pulse.Checker.Pure
module P = Pulse.Syntax.Printer
module N = Pulse.Syntax.Naming
module PS = Pulse.Checker.Prover.Substs
module Prover = Pulse.Checker.Prover
module Env = Pulse.Typing.Env
open Pulse.Show
module RU = Pulse.RuntimeUtils
let is_host_term (t:R.term) = not (R.Tv_Unknown? (R.inspect_ln t))
let debug_log = Pulse.Typing.debug_log "with_binders"
let option_must (f:option 'a) (msg:string) : T.Tac 'a =
match f with
| Some x -> x
| None -> T.fail msg
let rec refl_abs_binders (t:R.term) (acc:list binder) : T.Tac (list binder) =
let open R in
match inspect_ln t with
| Tv_Abs b body ->
let {sort; ppname} = R.inspect_binder b in
let sort = option_must (readback_ty sort)
(Printf.sprintf "Failed to readback elaborated binder sort %s in refl_abs_binders"
(T.term_to_string sort)) in
refl_abs_binders body
((mk_binder_ppname sort (mk_ppname ppname (RU.range_of_term t)))::acc)
| _ -> L.rev acc
let infer_binder_types (g:env) (bs:list binder) (v:vprop)
: T.Tac (list binder) =
match bs with
| [] -> []
| _ ->
let g = push_context g "infer_binder_types" v.range in
let tv = elab_term v in
if not (is_host_term tv)
then fail g (Some v.range)
(Printf.sprintf "assert.infer_binder_types: elaborated %s to %s, which failed the host term check"
(P.term_to_string v) (T.term_to_string tv));
let as_binder (b:binder) : R.binder =
let open R in
let bv : binder_view =
{ sort = elab_term b.binder_ty;
ppname = b.binder_ppname.name;
qual = Q_Explicit;
attrs = [] } in
pack_binder bv
in
let abstraction =
L.fold_right
(fun b (tv:host_term) ->
let b = as_binder b in
R.pack_ln (R.Tv_Abs b tv))
bs
tv
in
let inst_abstraction, _ = PC.instantiate_term_implicits g (tm_fstar abstraction v.range) in
match inst_abstraction.t with
| Tm_FStar t -> refl_abs_binders t []
| _ -> T.fail "Impossible: instantiated abstraction is not embedded F* term, please file a bug-report"
let rec open_binders (g:env) (bs:list binder) (uvs:env { disjoint uvs g }) (v:term) (body:st_term)
: T.Tac (uvs:env { disjoint uvs g } & term & st_term) =
match bs with
| [] -> (| uvs, v, body |)
| b::bs ->
// these binders are only lax checked so far
let _ = PC.check_universe (push_env g uvs) b.binder_ty in
let x = fresh (push_env g uvs) in
let ss = [ DT 0 (tm_var {nm_index=x;nm_ppname=b.binder_ppname}) ] in
let bs = L.mapi (fun i b ->
assume (i >= 0);
subst_binder b (shift_subst_n i ss)) bs in
let v = subst_term v (shift_subst_n (L.length bs) ss) in
let body = subst_st_term body (shift_subst_n (L.length bs) ss) in
open_binders g bs (push_binding uvs x b.binder_ppname b.binder_ty) v body | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Show.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.AssertWithBinders.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Show",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover",
"short_module": "Prover"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Naming",
"short_module": "N"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Pure",
"short_module": "PC"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"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": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"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 | bs: Prims.list ((Pulse.Syntax.Base.ppname * Pulse.Syntax.Base.var) * Pulse.Syntax.Base.typ)
-> Pulse.Syntax.Naming.subst | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple3",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.typ",
"FStar.Pervasives.Native.snd",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Pulse.Syntax.Naming.subst_elt",
"FStar.List.Tot.Base.fold_right",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Addition",
"Prims.Cons",
"Pulse.Syntax.Naming.ND",
"Prims.Nil",
"Pulse.Syntax.Naming.subst"
] | [] | false | false | false | true | false | let closing (bs: list (ppname & var & typ)) : subst =
| L.fold_right (fun (_, x, _) (n, ss) -> n + 1, (ND x n) :: ss) bs (0, []) |> snd | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.l_intro | val l_intro : _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | let l_intro () = forall_intro `or_else` implies_intro | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 91,
"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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.or_else",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.forall_intro",
"FStar.Tactics.V2.Logic.implies_intro"
] | [] | false | true | false | false | false | let l_intro () =
| forall_intro `or_else` implies_intro | false |
|
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.squash_intro | val squash_intro: Prims.unit -> Tac unit | val squash_intro: Prims.unit -> Tac unit | let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 97,
"start_col": 0,
"start_line": 96
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply"
] | [] | false | true | false | false | false | let squash_intro () : Tac unit =
| apply (`FStar.Squash.return_squash) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.forall_intro_as | val forall_intro_as (s: string) : Tac binding | val forall_intro_as (s: string) : Tac binding | let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 14,
"end_line": 58,
"start_col": 0,
"start_line": 56
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.string",
"FStar.Tactics.V2.Derived.intro_as",
"FStar.Tactics.NamedView.binding",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | false | true | false | false | false | let forall_intro_as (s: string) : Tac binding =
| apply_lemma (`fa_intro_lem);
intro_as s | false |
Hacl.Impl.K256.Verify.fst | Hacl.Impl.K256.Verify.load_signature | val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q))) | val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q))) | let load_signature r_q s_q signature =
let is_r_valid = QA.load_qelem_vartime r_q (sub signature 0ul 32ul) in
let is_s_valid = QA.load_qelem_vartime s_q (sub signature 32ul 32ul) in
is_r_valid && is_s_valid | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 188,
"start_col": 0,
"start_line": 185
} | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q))
let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame ()
val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x))
[@CInline]
let fmul_eq_vartime r z x =
push_frame ();
let tmp = create_felem () in
fmul tmp r z;
let h1 = ST.get () in
fnormalize tmp tmp;
let h2 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h1 tmp);
assert (inv_fully_reduced h2 tmp);
let b = is_felem_eq_vartime tmp x in
pop_frame ();
b
inline_for_extraction noextract
val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_avoid_finv p r =
let h0 = ST.get () in
let x, y, z = getx p, gety p, getz p in
push_frame ();
let r_bytes = create 32ul (u8 0) in
let r_fe = create_felem () in
let tmp_q = create_felem () in
let tmp_x = create_felem () in
QA.store_qelem r_bytes r;
load_felem r_fe r_bytes;
let h1 = ST.get () in
assert (modifies (loc r_fe) h0 h1);
//assert (inv_fully_reduced h1 r_fe);
//assert (as_nat h1 r_fe == qas_nat h1 r);
let h2 = ST.get () in
fnormalize tmp_x x;
let h3 = ST.get () in
assert (modifies (loc tmp_x) h2 h3);
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h2 x);
//assert (inv_fully_reduced h3 tmp_x);
//assert (inv_lazy_reduced2 h3 z);
let is_rz_x = fmul_eq_vartime r_fe z tmp_x in
//assert (is_rz_x == (S.fmul (as_nat h3 r_fe) (feval h3 z) = as_nat h3 tmp_x));
let res : bool =
if not is_rz_x then begin
let is_r_lt_p_m_q = is_felem_lt_prime_minus_order_vartime r_fe in
if is_r_lt_p_m_q then begin
assert (as_nat h1 r_fe < S.prime - S.q);
make_u52_5 tmp_q (make_order_k256 ());
let h4 = ST.get () in
BL.add5_lemma (1,1,1,1,1) (1,1,1,1,1) (as_felem5 h4 r_fe) (as_felem5 h4 tmp_q);
fadd tmp_q r_fe tmp_q;
fmul_eq_vartime tmp_q z tmp_x end
//assert (is_rqz_x == (S.fmul (feval h5 tmp) (feval h5 z) = as_nat h5 tmp_x));
else false end
else true in
let h4 = ST.get () in
assert (modifies (loc tmp_q) h3 h4);
pop_frame ();
KL.ecdsa_verify_avoid_finv (point_eval h0 p) (QA.qas_nat h0 r);
assert (res <==> (S.fmul (feval h0 x) (S.finv (feval h0 z)) % S.q = QA.qas_nat h0 r));
let h5 = ST.get () in
assert (modifies0 h0 h5);
res
inline_for_extraction noextract
val ecdsa_verify_cmpr: r:QA.qelem -> pk:point -> u1:QA.qelem -> u2:QA.qelem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ QA.qas_nat h u1 < S.q /\ QA.qas_nat h u2 < S.q /\
0 < QA.qas_nat h r /\ QA.qas_nat h r < S.q)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk) in
b <==> (if S.is_proj_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_cmpr r pk u1 u2 =
push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_g_double_split_lambda_vartime res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (point_eval h1 res) ==
S.to_aff_point (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk)));
KL.lemma_aff_is_point_at_inf (point_eval h1 res);
KL.lemma_aff_is_point_at_inf (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk));
let b =
if is_proj_point_at_inf_vartime res then false
else ecdsa_verify_avoid_finv res r in
pop_frame ();
b
inline_for_extraction noextract
val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q))) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"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.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"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 |
r_q: Hacl.K256.Scalar.qelem ->
s_q: Hacl.K256.Scalar.qelem ->
signature: Hacl.Impl.K256.Verify.lbytes 64ul
-> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.Impl.K256.Verify.lbytes",
"FStar.UInt32.__uint_to_t",
"Prims.op_AmpAmp",
"Prims.bool",
"Hacl.K256.Scalar.load_qelem_vartime",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Lib.IntTypes.uint8"
] | [] | false | true | false | false | false | let load_signature r_q s_q signature =
| let is_r_valid = QA.load_qelem_vartime r_q (sub signature 0ul 32ul) in
let is_s_valid = QA.load_qelem_vartime s_q (sub signature 32ul 32ul) in
is_r_valid && is_s_valid | false |
Pulse.Checker.AssertWithBinders.fst | Pulse.Checker.AssertWithBinders.refl_abs_binders | val refl_abs_binders (t: R.term) (acc: list binder) : T.Tac (list binder) | val refl_abs_binders (t: R.term) (acc: list binder) : T.Tac (list binder) | let rec refl_abs_binders (t:R.term) (acc:list binder) : T.Tac (list binder) =
let open R in
match inspect_ln t with
| Tv_Abs b body ->
let {sort; ppname} = R.inspect_binder b in
let sort = option_must (readback_ty sort)
(Printf.sprintf "Failed to readback elaborated binder sort %s in refl_abs_binders"
(T.term_to_string sort)) in
refl_abs_binders body
((mk_binder_ppname sort (mk_ppname ppname (RU.range_of_term t)))::acc)
| _ -> L.rev acc | {
"file_name": "lib/steel/pulse/Pulse.Checker.AssertWithBinders.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 18,
"end_line": 56,
"start_col": 0,
"start_line": 46
} | (*
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.AssertWithBinders
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Elaborate.Pure
open Pulse.Typing.Env
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module PC = Pulse.Checker.Pure
module P = Pulse.Syntax.Printer
module N = Pulse.Syntax.Naming
module PS = Pulse.Checker.Prover.Substs
module Prover = Pulse.Checker.Prover
module Env = Pulse.Typing.Env
open Pulse.Show
module RU = Pulse.RuntimeUtils
let is_host_term (t:R.term) = not (R.Tv_Unknown? (R.inspect_ln t))
let debug_log = Pulse.Typing.debug_log "with_binders"
let option_must (f:option 'a) (msg:string) : T.Tac 'a =
match f with
| Some x -> x
| None -> T.fail msg | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Show.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.AssertWithBinders.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Show",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover",
"short_module": "Prover"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Naming",
"short_module": "N"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Pure",
"short_module": "PC"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"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": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"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 | t: FStar.Stubs.Reflection.Types.term -> acc: Prims.list Pulse.Syntax.Base.binder
-> FStar.Tactics.Effect.Tac (Prims.list Pulse.Syntax.Base.binder) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"Pulse.Syntax.Base.binder",
"FStar.Stubs.Reflection.V2.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Stubs.Reflection.V2.Data.ppname_t",
"Pulse.Checker.AssertWithBinders.refl_abs_binders",
"Prims.Cons",
"Pulse.Syntax.Base.mk_binder_ppname",
"Pulse.Syntax.Base.mk_ppname",
"Pulse.RuntimeUtils.range_of_term",
"Pulse.Syntax.Base.term",
"Prims.eq2",
"Pulse.Elaborate.Pure.elab_term",
"Pulse.Checker.AssertWithBinders.option_must",
"Pulse.Readback.readback_ty",
"Prims.string",
"FStar.Printf.sprintf",
"FStar.Stubs.Tactics.V2.Builtins.term_to_string",
"FStar.Stubs.Reflection.V2.Data.binder_view",
"Prims.precedes",
"FStar.Stubs.Reflection.V2.Builtins.inspect_binder",
"FStar.Stubs.Reflection.V2.Data.term_view",
"FStar.List.Tot.Base.rev"
] | [
"recursion"
] | false | true | false | false | false | let rec refl_abs_binders (t: R.term) (acc: list binder) : T.Tac (list binder) =
| let open R in
match inspect_ln t with
| Tv_Abs b body ->
let { sort = sort ; ppname = ppname } = R.inspect_binder b in
let sort =
option_must (readback_ty sort)
(Printf.sprintf "Failed to readback elaborated binder sort %s in refl_abs_binders"
(T.term_to_string sort))
in
refl_abs_binders body ((mk_binder_ppname sort (mk_ppname ppname (RU.range_of_term t))) :: acc)
| _ -> L.rev acc | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.l_intros | val l_intros : _: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | let l_intros () = repeat l_intro | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 94,
"start_col": 0,
"start_line": 94
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.repeat",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.l_intro",
"Prims.list"
] | [] | false | true | false | false | false | let l_intros () =
| repeat l_intro | false |
|
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.l_exact | val l_exact : t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 101,
"start_col": 0,
"start_line": 99
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.try_with",
"Prims.unit",
"FStar.Tactics.V2.Derived.exact",
"Prims.exn",
"FStar.Tactics.V2.Logic.squash_intro"
] | [] | false | true | false | false | false | let l_exact (t: term) =
| try exact t
with
| _ ->
(squash_intro ();
exact t) | false |
|
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.implies_intros | val implies_intros: Prims.unit -> Tac (list binding) | val implies_intros: Prims.unit -> Tac (list binding) | let implies_intros () : Tac (list binding) = repeat1 implies_intro | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 66,
"end_line": 88,
"start_col": 0,
"start_line": 88
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.repeat1",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.implies_intro",
"Prims.list"
] | [] | false | true | false | false | false | let implies_intros () : Tac (list binding) =
| repeat1 implies_intro | false |
Hacl.Impl.K256.Verify.fst | Hacl.Impl.K256.Verify.ecdsa_verify_get_u12 | val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q)) | val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q)) | let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame () | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 48,
"start_col": 0,
"start_line": 42
} | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"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.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"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 |
u1: Hacl.K256.Scalar.qelem ->
u2: Hacl.K256.Scalar.qelem ->
r: Hacl.K256.Scalar.qelem ->
s: Hacl.K256.Scalar.qelem ->
z: Hacl.K256.Scalar.qelem
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.K256.Scalar.qmul",
"Hacl.Impl.K256.Qinv.qinv",
"Hacl.K256.Scalar.create_qelem",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let ecdsa_verify_get_u12 u1 u2 r s z =
| push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame () | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.hyp | val hyp (x: namedv) : Tac unit | val hyp (x: namedv) : Tac unit | let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 105,
"start_col": 0,
"start_line": 105
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general... | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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: FStar.Tactics.NamedView.namedv -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.namedv",
"FStar.Tactics.V2.Logic.l_exact",
"FStar.Tactics.V2.SyntaxCoercions.namedv_to_term",
"Prims.unit"
] | [] | false | true | false | false | false | let hyp (x: namedv) : Tac unit =
| l_exact (namedv_to_term x) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.explode | val explode: Prims.unit -> Tac unit | val explode: Prims.unit -> Tac unit | let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))])) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 64,
"end_line": 135,
"start_col": 0,
"start_line": 132
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Pervasives.ignore",
"FStar.Tactics.V2.Derived.repeatseq",
"FStar.Tactics.V2.Derived.first",
"Prims.Cons",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.l_intro",
"FStar.Tactics.V2.Logic.split",
"Prims.Nil"
] | [] | false | true | false | false | false | let explode () : Tac unit =
| ignore (repeatseq (fun () -> first [(fun () -> ignore (l_intro ())); (fun () -> ignore (split ()))])
) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.pose_lemma | val pose_lemma (t: term) : Tac binding | val pose_lemma (t: term) : Tac binding | let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 130,
"start_col": 0,
"start_line": 111
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Stubs.Reflection.Types.term",
"FStar.Tactics.V2.Derived.pose",
"FStar.Tactics.NamedView.binding",
"FStar.Reflection.V2.Formula.formula",
"Prims.unit",
"FStar.Pervasives.ignore",
"FStar.Pervasives.Native.option",
"FStar.Tactics.V2.Derived.trytac",
"FStar.Tactics.V2.Derived.trivial",
"FStar.Tactics.V2.Derived.flip",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_term",
"FStar.Tactics.V2.Derived.tcut",
"FStar.Reflection.V2.Formula.term_as_formula'",
"FStar.Tactics.V2.Derived.norm_term",
"Prims.Nil",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V2.Data.comp_view",
"FStar.Tactics.V2.Derived.fail",
"FStar.Tactics.NamedView.comp",
"FStar.Tactics.NamedView.tcc",
"FStar.Stubs.Reflection.Types.env",
"FStar.Tactics.V2.Derived.cur_env"
] | [] | false | true | false | false | false | let pose_lemma (t: term) : Tac binding =
| let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in
let post = norm_term [] post in
match term_as_formula' pre with
| True_ -> pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.cases_or | val cases_or (o: term) : Tac unit | val cases_or (o: term) : Tac unit | let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o]) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 219,
"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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | o: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.apply_lemma",
"FStar.Reflection.V2.Derived.mk_e_app",
"Prims.Cons",
"FStar.Stubs.Reflection.Types.term",
"Prims.Nil",
"Prims.unit"
] | [] | false | true | false | false | false | let cases_or (o: term) : Tac unit =
| apply_lemma (mk_e_app (`or_ind) [o]) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.rewrite_all_equalities | val rewrite_all_equalities: Prims.unit -> Tac unit | val rewrite_all_equalities: Prims.unit -> Tac unit | let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 170,
"start_col": 0,
"start_line": 169
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Logic.visit",
"FStar.Tactics.V2.Logic.simplify_eq_implication"
] | [] | false | true | false | false | false | let rewrite_all_equalities () : Tac unit =
| visit simplify_eq_implication | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.unsquash | val unsquash (t: term) : Tac term | val unsquash (t: term) : Tac term | let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 209,
"start_col": 0,
"start_line": 205
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.term | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.NamedView.pack",
"FStar.Tactics.NamedView.Tv_Var",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_namedv",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Stubs.Tactics.V2.Builtins.intro",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma",
"FStar.Reflection.V2.Derived.mk_e_app",
"Prims.Cons",
"FStar.Stubs.Reflection.Types.term",
"Prims.Nil"
] | [] | false | true | false | false | false | let unsquash (t: term) : Tac term =
| let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.visit | val visit (callback: (unit -> Tac unit)) : Tac unit | val visit (callback: (unit -> Tac unit)) : Tac unit | let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 154,
"start_col": 0,
"start_line": 137
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))])) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | callback: (_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit)
-> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.focus",
"FStar.Tactics.V2.Derived.or_else",
"FStar.Tactics.NamedView.bv",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.seq",
"FStar.Tactics.V2.Logic.visit",
"FStar.Tactics.V2.Logic.l_revert_all",
"Prims.list",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.forall_intros",
"FStar.Tactics.V2.Logic.split",
"FStar.Tactics.V2.Logic.l_revert",
"FStar.Tactics.V2.Logic.implies_intro",
"FStar.Reflection.V2.Formula.formula",
"FStar.Reflection.V2.Formula.term_as_formula",
"FStar.Tactics.V2.Derived.cur_goal"
] | [
"recursion"
] | false | true | false | false | false | let rec visit (callback: (unit -> Tac unit)) : Tac unit =
| focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q -> seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ -> ())) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.cases_bool | val cases_bool (b: term) : Tac unit | val cases_bool (b: term) : Tac unit | let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ()) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 104,
"end_line": 229,
"start_col": 0,
"start_line": 226
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | b: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.seq",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma",
"FStar.Reflection.V2.Derived.mk_e_app",
"Prims.Cons",
"FStar.Stubs.Reflection.Types.term",
"Prims.Nil",
"FStar.Pervasives.Native.option",
"FStar.Tactics.V2.Derived.trytac",
"FStar.Stubs.Tactics.V2.Builtins.clear_top",
"FStar.Stubs.Tactics.V2.Builtins.rewrite",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.implies_intro"
] | [] | false | true | false | false | false | let cases_bool (b: term) : Tac unit =
| let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () ->
let _ =
trytac (fun () ->
let b = implies_intro () in
rewrite b;
clear_top ())
in
()) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.left | val left: Prims.unit -> Tac unit | val left: Prims.unit -> Tac unit | let left () : Tac unit =
apply_lemma (`or_intro_1) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 238,
"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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | false | true | false | false | false | let left () : Tac unit =
| apply_lemma (`or_intro_1) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.right | val right: Prims.unit -> Tac unit | val right: Prims.unit -> Tac unit | let right () : Tac unit =
apply_lemma (`or_intro_2) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 241,
"start_col": 0,
"start_line": 240
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | false | true | false | false | false | let right () : Tac unit =
| apply_lemma (`or_intro_2) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.revert_squash | val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x) | val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x) | let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in () | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 33,
"start_col": 0,
"start_line": 33
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | s: Prims.squash (forall (x: a). b x) -> x: a -> Prims.squash (b x) | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.l_Forall",
"Prims.unit"
] | [] | false | false | true | false | false | let revert_squash #a #b s x =
| let x:(_: unit{forall x. b x}) = s in
() | false |
Pulse.Checker.AssertWithBinders.fst | Pulse.Checker.AssertWithBinders.add_rem_uvs | val add_rem_uvs (g: env) (t: typ) (uvs: env{Env.disjoint g uvs}) (v: vprop)
: T.Tac (uvs: env{Env.disjoint g uvs} & vprop) | val add_rem_uvs (g: env) (t: typ) (uvs: env{Env.disjoint g uvs}) (v: vprop)
: T.Tac (uvs: env{Env.disjoint g uvs} & vprop) | let rec add_rem_uvs (g:env) (t:typ) (uvs:env { Env.disjoint g uvs }) (v:vprop)
: T.Tac (uvs:env { Env.disjoint g uvs } & vprop) =
match is_arrow t with
| None -> (| uvs, v |)
| Some (b, qopt, c) ->
let x = fresh (push_env g uvs) in
let ct = open_comp_nv c (b.binder_ppname, x) in
let uvs = Env.push_binding uvs x b.binder_ppname b.binder_ty in
let v = tm_pureapp v qopt (tm_var {nm_index = x; nm_ppname = b.binder_ppname}) in
add_rem_uvs g (comp_res ct) uvs v | {
"file_name": "lib/steel/pulse/Pulse.Checker.AssertWithBinders.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 349,
"start_col": 0,
"start_line": 340
} | (*
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.AssertWithBinders
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Elaborate.Pure
open Pulse.Typing.Env
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module PC = Pulse.Checker.Pure
module P = Pulse.Syntax.Printer
module N = Pulse.Syntax.Naming
module PS = Pulse.Checker.Prover.Substs
module Prover = Pulse.Checker.Prover
module Env = Pulse.Typing.Env
open Pulse.Show
module RU = Pulse.RuntimeUtils
let is_host_term (t:R.term) = not (R.Tv_Unknown? (R.inspect_ln t))
let debug_log = Pulse.Typing.debug_log "with_binders"
let option_must (f:option 'a) (msg:string) : T.Tac 'a =
match f with
| Some x -> x
| None -> T.fail msg
let rec refl_abs_binders (t:R.term) (acc:list binder) : T.Tac (list binder) =
let open R in
match inspect_ln t with
| Tv_Abs b body ->
let {sort; ppname} = R.inspect_binder b in
let sort = option_must (readback_ty sort)
(Printf.sprintf "Failed to readback elaborated binder sort %s in refl_abs_binders"
(T.term_to_string sort)) in
refl_abs_binders body
((mk_binder_ppname sort (mk_ppname ppname (RU.range_of_term t)))::acc)
| _ -> L.rev acc
let infer_binder_types (g:env) (bs:list binder) (v:vprop)
: T.Tac (list binder) =
match bs with
| [] -> []
| _ ->
let g = push_context g "infer_binder_types" v.range in
let tv = elab_term v in
if not (is_host_term tv)
then fail g (Some v.range)
(Printf.sprintf "assert.infer_binder_types: elaborated %s to %s, which failed the host term check"
(P.term_to_string v) (T.term_to_string tv));
let as_binder (b:binder) : R.binder =
let open R in
let bv : binder_view =
{ sort = elab_term b.binder_ty;
ppname = b.binder_ppname.name;
qual = Q_Explicit;
attrs = [] } in
pack_binder bv
in
let abstraction =
L.fold_right
(fun b (tv:host_term) ->
let b = as_binder b in
R.pack_ln (R.Tv_Abs b tv))
bs
tv
in
let inst_abstraction, _ = PC.instantiate_term_implicits g (tm_fstar abstraction v.range) in
match inst_abstraction.t with
| Tm_FStar t -> refl_abs_binders t []
| _ -> T.fail "Impossible: instantiated abstraction is not embedded F* term, please file a bug-report"
let rec open_binders (g:env) (bs:list binder) (uvs:env { disjoint uvs g }) (v:term) (body:st_term)
: T.Tac (uvs:env { disjoint uvs g } & term & st_term) =
match bs with
| [] -> (| uvs, v, body |)
| b::bs ->
// these binders are only lax checked so far
let _ = PC.check_universe (push_env g uvs) b.binder_ty in
let x = fresh (push_env g uvs) in
let ss = [ DT 0 (tm_var {nm_index=x;nm_ppname=b.binder_ppname}) ] in
let bs = L.mapi (fun i b ->
assume (i >= 0);
subst_binder b (shift_subst_n i ss)) bs in
let v = subst_term v (shift_subst_n (L.length bs) ss) in
let body = subst_st_term body (shift_subst_n (L.length bs) ss) in
open_binders g bs (push_binding uvs x b.binder_ppname b.binder_ty) v body
let closing (bs:list (ppname & var & typ)) : subst =
L.fold_right (fun (_, x, _) (n, ss) ->
n+1,
(ND x n)::ss
) bs (0, []) |> snd
let rec close_binders (bs:list (ppname & var & typ))
: Tot (list binder) (decreases L.length bs) =
match bs with
| [] -> []
| (name, x, t)::bs ->
let bss = L.mapi (fun n (n1, x1, t1) ->
assume (n >= 0);
n1, x1, subst_term t1 [ND x n]) bs in
let b = mk_binder_ppname t name in
assume (L.length bss == L.length bs);
b::(close_binders bss)
let unfold_defs (g:env) (defs:option (list string)) (t:term)
: T.Tac term
= let t = elab_term t in
let head, _ = T.collect_app t in
match R.inspect_ln head with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
let head = String.concat "." (R.inspect_fv fv) in
let fully =
match defs with
| Some defs -> defs
| None -> []
in
let rt = RU.unfold_def (fstar_env g) head fully t in
let rt = option_must rt
(Printf.sprintf "unfolding %s returned None" (T.term_to_string t)) in
let ty = option_must (readback_ty rt)
(Printf.sprintf "error in reading back the unfolded term %s" (T.term_to_string rt)) in
debug_log g (fun _ -> Printf.sprintf "Unfolded %s to F* term %s and readback as %s" (T.term_to_string t) (T.term_to_string rt) (P.term_to_string ty));
ty
)
| _ ->
fail g (Some (RU.range_of_term t))
(Printf.sprintf "Cannot unfold %s, the head is not an fvar" (T.term_to_string t))
let check_unfoldable g (v:term) : T.Tac unit =
match v.t with
| Tm_FStar _ -> ()
| _ ->
fail g
(Some v.range)
(Printf.sprintf "`fold` and `unfold` expect a single user-defined predicate as an argument, \
but %s is a primitive term that cannot be folded or unfolded"
(P.term_to_string v))
let visit_and_rewrite (p: (R.term & R.term)) (t:term) : T.Tac term =
let open FStar.Reflection.V2.TermEq in
let lhs, rhs = p in
let visitor (t:R.term) : T.Tac R.term =
if term_eq t lhs then rhs else t
in
match R.inspect_ln lhs with
| R.Tv_Var n -> (
let nv = R.inspect_namedv n in
assume (is_host_term rhs);
subst_term t [NT nv.uniq { t = Tm_FStar rhs; range = t.range }]
)
| _ ->
let rec aux (t:term) : T.Tac term =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Inames
| Tm_Unknown -> t
| Tm_Inv i ->
{ t with t = Tm_Inv (aux i) }
| Tm_AddInv i is ->
{ t with t = Tm_AddInv (aux i) (aux is) }
| Tm_Pure p -> { t with t = Tm_Pure (aux p) }
| Tm_Star l r -> { t with t = Tm_Star (aux l) (aux r) }
| Tm_ExistsSL u b body -> { t with t = Tm_ExistsSL u { b with binder_ty=aux b.binder_ty} (aux body) }
| Tm_ForallSL u b body -> { t with t = Tm_ForallSL u { b with binder_ty=aux b.binder_ty} (aux body) }
| Tm_FStar h ->
let h = FStar.Tactics.Visit.visit_tm visitor h in
assume (is_host_term h);
{ t with t=Tm_FStar h }
in
aux t
let visit_and_rewrite_conjuncts (p: (R.term & R.term)) (tms:list term) : T.Tac (list term) =
T.map (visit_and_rewrite p) tms
let visit_and_rewrite_conjuncts_all (p: list (R.term & R.term)) (goal:term) : T.Tac (term & term) =
let tms = Pulse.Typing.Combinators.vprop_as_list goal in
let tms' = T.fold_left (fun tms p -> visit_and_rewrite_conjuncts p tms) tms p in
assume (L.length tms' == L.length tms);
let lhs, rhs =
T.fold_left2
(fun (lhs, rhs) t t' ->
if eq_tm t t' then lhs, rhs
else (t::lhs, t'::rhs))
([], [])
tms tms'
in
Pulse.Typing.Combinators.list_as_vprop lhs,
Pulse.Typing.Combinators.list_as_vprop rhs
let disjoint (dom:list var) (cod:Set.set var) =
L.for_all (fun d -> not (Set.mem d cod)) dom
let rec as_subst (p : list (term & term))
(out:list subst_elt)
(domain:list var)
(codomain:Set.set var)
: option (list subst_elt) =
match p with
| [] ->
if disjoint domain codomain
then Some out
else None
| (e1, e2)::p -> (
match e1.t with
| Tm_FStar e1 -> (
match R.inspect_ln e1 with
| R.Tv_Var n -> (
let nv = R.inspect_namedv n in
as_subst p
(NT nv.uniq e2::out)
(nv.uniq ::domain )
(Set.union codomain (freevars e2))
)
| _ -> None
)
| _ -> None
)
let rewrite_all (g:env) (p: list (term & term)) (t:term) : T.Tac (term & term) =
match as_subst p [] [] Set.empty with
| Some s ->
t, subst_term t s
| _ ->
let p : list (R.term & R.term) =
T.map
(fun (e1, e2) ->
elab_term (fst (Pulse.Checker.Pure.instantiate_term_implicits g e1)),
elab_term (fst (Pulse.Checker.Pure.instantiate_term_implicits g e2)))
p
in
let lhs, rhs = visit_and_rewrite_conjuncts_all p t in
debug_log g (fun _ -> Printf.sprintf "Rewrote %s to %s" (P.term_to_string lhs) (P.term_to_string rhs));
lhs, rhs
let check_renaming
(g:env)
(pre:term)
(st:st_term {
match st.term with
| Tm_ProofHintWithBinders { hint_type = RENAME _ } -> true
| _ -> false
})
: T.Tac st_term
= let Tm_ProofHintWithBinders ht = st.term in
let { hint_type=RENAME { pairs; goal }; binders=bs; t=body } = ht in
match bs, goal with
| _::_, None ->
//if there are binders, we must have a goal
fail g (Some st.range) "A renaming with binders must have a goal (with xs. rename ... in goal)"
| _::_, Some goal ->
//rewrite it as
// with bs. assert goal;
// rename [pairs] in goal;
// ...
let body = {st with term = Tm_ProofHintWithBinders { ht with binders = [] }} in
{ st with term = Tm_ProofHintWithBinders { hint_type=ASSERT { p = goal }; binders=bs; t=body } }
| [], None ->
// if there is no goal, take the goal to be the full current pre
let lhs, rhs = rewrite_all g pairs pre in
let t = { st with term = Tm_Rewrite { t1 = lhs; t2 = rhs } } in
{ st with term = Tm_Bind { binder = as_binder tm_unit; head = t; body } }
| [], Some goal -> (
let goal, _ = PC.instantiate_term_implicits g goal in
let lhs, rhs = rewrite_all g pairs goal in
let t = { st with term = Tm_Rewrite { t1 = lhs; t2 = rhs } } in
{ st with term = Tm_Bind { binder = as_binder tm_unit; head = t; body } }
)
let check_wild
(g:env)
(pre:term)
(st:st_term { head_wild st })
: T.Tac st_term
= let Tm_ProofHintWithBinders ht = st.term in
let { binders=bs; t=body } = ht in
match bs with
| [] ->
fail g (Some st.range) "A wildcard must have at least one binder"
| _ ->
let vprops = Pulse.Typing.Combinators.vprop_as_list pre in
let ex, rest = List.Tot.partition (fun (v:vprop) -> Tm_ExistsSL? v.t) vprops in
match ex with
| []
| _::_::_ ->
fail g (Some st.range) "Binding names with a wildcard requires exactly one existential quantifier in the goal"
| [ex] ->
let k = List.Tot.length bs in
let rec peel_binders (n:nat) (t:term) : T.Tac st_term =
if n = 0
then (
let ex_body = t in
{ st with term = Tm_ProofHintWithBinders { ht with hint_type = ASSERT { p = ex_body } }}
)
else (
match t.t with
| Tm_ExistsSL u b body -> peel_binders (n-1) body
| _ ->
fail g (Some st.range)
(Printf.sprintf "Expected an existential quantifier with at least %d binders; but only found %s with %d binders"
k (show ex) (k - n))
)
in
peel_binders k ex
//
// v is a partially applied vprop with type t
// add uvars for the remaining arguments | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Show.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.AssertWithBinders.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Show",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover",
"short_module": "Prover"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Naming",
"short_module": "N"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Pure",
"short_module": "PC"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"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": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"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 ->
t: Pulse.Syntax.Base.typ ->
uvs: Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint g uvs} ->
v: Pulse.Syntax.Base.vprop
-> FStar.Tactics.Effect.Tac
(Prims.dtuple2 (uvs: Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint g uvs})
(fun _ -> Pulse.Syntax.Base.vprop)) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.Env.disjoint",
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Pure.is_arrow",
"Prims.Mkdtuple2",
"Prims.dtuple2",
"Pulse.Syntax.Base.binder",
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.qualifier",
"Pulse.Syntax.Base.comp",
"Pulse.Checker.AssertWithBinders.add_rem_uvs",
"Pulse.Syntax.Base.comp_res",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.tm_pureapp",
"Pulse.Syntax.Pure.tm_var",
"Pulse.Syntax.Base.Mknm",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname",
"Prims.eq2",
"FStar.Reflection.Typing.fstar_top_env",
"Pulse.Typing.Env.fstar_env",
"Pulse.Typing.Env.push_binding",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Syntax.Naming.open_comp_nv",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.var",
"Prims.l_not",
"Prims.b2t",
"FStar.Set.mem",
"Pulse.Typing.Env.dom",
"Pulse.Typing.Env.push_env",
"Pulse.Typing.Env.fresh"
] | [
"recursion"
] | false | true | false | false | false | let rec add_rem_uvs (g: env) (t: typ) (uvs: env{Env.disjoint g uvs}) (v: vprop)
: T.Tac (uvs: env{Env.disjoint g uvs} & vprop) =
| match is_arrow t with
| None -> (| uvs, v |)
| Some (b, qopt, c) ->
let x = fresh (push_env g uvs) in
let ct = open_comp_nv c (b.binder_ppname, x) in
let uvs = Env.push_binding uvs x b.binder_ppname b.binder_ty in
let v = tm_pureapp v qopt (tm_var ({ nm_index = x; nm_ppname = b.binder_ppname })) in
add_rem_uvs g (comp_res ct) uvs v | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.l_revert_all | val l_revert_all (bs: list binding) : Tac unit | val l_revert_all (bs: list binding) : Tac unit | let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 44,
"start_col": 0,
"start_line": 41
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | bs: Prims.list FStar.Tactics.NamedView.binding -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Tactics.NamedView.binding",
"Prims.unit",
"FStar.Tactics.V2.Logic.l_revert_all",
"FStar.Tactics.V2.Logic.l_revert"
] | [
"recursion"
] | false | true | false | false | false | let rec l_revert_all (bs: list binding) : Tac unit =
| match bs with
| [] -> ()
| _ :: tl ->
l_revert ();
l_revert_all tl | false |
Pulse.Checker.AssertWithBinders.fst | Pulse.Checker.AssertWithBinders.rewrite_all | val rewrite_all (g: env) (p: list (term & term)) (t: term) : T.Tac (term & term) | val rewrite_all (g: env) (p: list (term & term)) (t: term) : T.Tac (term & term) | let rewrite_all (g:env) (p: list (term & term)) (t:term) : T.Tac (term & term) =
match as_subst p [] [] Set.empty with
| Some s ->
t, subst_term t s
| _ ->
let p : list (R.term & R.term) =
T.map
(fun (e1, e2) ->
elab_term (fst (Pulse.Checker.Pure.instantiate_term_implicits g e1)),
elab_term (fst (Pulse.Checker.Pure.instantiate_term_implicits g e2)))
p
in
let lhs, rhs = visit_and_rewrite_conjuncts_all p t in
debug_log g (fun _ -> Printf.sprintf "Rewrote %s to %s" (P.term_to_string lhs) (P.term_to_string rhs));
lhs, rhs | {
"file_name": "lib/steel/pulse/Pulse.Checker.AssertWithBinders.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 12,
"end_line": 260,
"start_col": 0,
"start_line": 246
} | (*
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.AssertWithBinders
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Elaborate.Pure
open Pulse.Typing.Env
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module R = FStar.Reflection.V2
module PC = Pulse.Checker.Pure
module P = Pulse.Syntax.Printer
module N = Pulse.Syntax.Naming
module PS = Pulse.Checker.Prover.Substs
module Prover = Pulse.Checker.Prover
module Env = Pulse.Typing.Env
open Pulse.Show
module RU = Pulse.RuntimeUtils
let is_host_term (t:R.term) = not (R.Tv_Unknown? (R.inspect_ln t))
let debug_log = Pulse.Typing.debug_log "with_binders"
let option_must (f:option 'a) (msg:string) : T.Tac 'a =
match f with
| Some x -> x
| None -> T.fail msg
let rec refl_abs_binders (t:R.term) (acc:list binder) : T.Tac (list binder) =
let open R in
match inspect_ln t with
| Tv_Abs b body ->
let {sort; ppname} = R.inspect_binder b in
let sort = option_must (readback_ty sort)
(Printf.sprintf "Failed to readback elaborated binder sort %s in refl_abs_binders"
(T.term_to_string sort)) in
refl_abs_binders body
((mk_binder_ppname sort (mk_ppname ppname (RU.range_of_term t)))::acc)
| _ -> L.rev acc
let infer_binder_types (g:env) (bs:list binder) (v:vprop)
: T.Tac (list binder) =
match bs with
| [] -> []
| _ ->
let g = push_context g "infer_binder_types" v.range in
let tv = elab_term v in
if not (is_host_term tv)
then fail g (Some v.range)
(Printf.sprintf "assert.infer_binder_types: elaborated %s to %s, which failed the host term check"
(P.term_to_string v) (T.term_to_string tv));
let as_binder (b:binder) : R.binder =
let open R in
let bv : binder_view =
{ sort = elab_term b.binder_ty;
ppname = b.binder_ppname.name;
qual = Q_Explicit;
attrs = [] } in
pack_binder bv
in
let abstraction =
L.fold_right
(fun b (tv:host_term) ->
let b = as_binder b in
R.pack_ln (R.Tv_Abs b tv))
bs
tv
in
let inst_abstraction, _ = PC.instantiate_term_implicits g (tm_fstar abstraction v.range) in
match inst_abstraction.t with
| Tm_FStar t -> refl_abs_binders t []
| _ -> T.fail "Impossible: instantiated abstraction is not embedded F* term, please file a bug-report"
let rec open_binders (g:env) (bs:list binder) (uvs:env { disjoint uvs g }) (v:term) (body:st_term)
: T.Tac (uvs:env { disjoint uvs g } & term & st_term) =
match bs with
| [] -> (| uvs, v, body |)
| b::bs ->
// these binders are only lax checked so far
let _ = PC.check_universe (push_env g uvs) b.binder_ty in
let x = fresh (push_env g uvs) in
let ss = [ DT 0 (tm_var {nm_index=x;nm_ppname=b.binder_ppname}) ] in
let bs = L.mapi (fun i b ->
assume (i >= 0);
subst_binder b (shift_subst_n i ss)) bs in
let v = subst_term v (shift_subst_n (L.length bs) ss) in
let body = subst_st_term body (shift_subst_n (L.length bs) ss) in
open_binders g bs (push_binding uvs x b.binder_ppname b.binder_ty) v body
let closing (bs:list (ppname & var & typ)) : subst =
L.fold_right (fun (_, x, _) (n, ss) ->
n+1,
(ND x n)::ss
) bs (0, []) |> snd
let rec close_binders (bs:list (ppname & var & typ))
: Tot (list binder) (decreases L.length bs) =
match bs with
| [] -> []
| (name, x, t)::bs ->
let bss = L.mapi (fun n (n1, x1, t1) ->
assume (n >= 0);
n1, x1, subst_term t1 [ND x n]) bs in
let b = mk_binder_ppname t name in
assume (L.length bss == L.length bs);
b::(close_binders bss)
let unfold_defs (g:env) (defs:option (list string)) (t:term)
: T.Tac term
= let t = elab_term t in
let head, _ = T.collect_app t in
match R.inspect_ln head with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
let head = String.concat "." (R.inspect_fv fv) in
let fully =
match defs with
| Some defs -> defs
| None -> []
in
let rt = RU.unfold_def (fstar_env g) head fully t in
let rt = option_must rt
(Printf.sprintf "unfolding %s returned None" (T.term_to_string t)) in
let ty = option_must (readback_ty rt)
(Printf.sprintf "error in reading back the unfolded term %s" (T.term_to_string rt)) in
debug_log g (fun _ -> Printf.sprintf "Unfolded %s to F* term %s and readback as %s" (T.term_to_string t) (T.term_to_string rt) (P.term_to_string ty));
ty
)
| _ ->
fail g (Some (RU.range_of_term t))
(Printf.sprintf "Cannot unfold %s, the head is not an fvar" (T.term_to_string t))
let check_unfoldable g (v:term) : T.Tac unit =
match v.t with
| Tm_FStar _ -> ()
| _ ->
fail g
(Some v.range)
(Printf.sprintf "`fold` and `unfold` expect a single user-defined predicate as an argument, \
but %s is a primitive term that cannot be folded or unfolded"
(P.term_to_string v))
let visit_and_rewrite (p: (R.term & R.term)) (t:term) : T.Tac term =
let open FStar.Reflection.V2.TermEq in
let lhs, rhs = p in
let visitor (t:R.term) : T.Tac R.term =
if term_eq t lhs then rhs else t
in
match R.inspect_ln lhs with
| R.Tv_Var n -> (
let nv = R.inspect_namedv n in
assume (is_host_term rhs);
subst_term t [NT nv.uniq { t = Tm_FStar rhs; range = t.range }]
)
| _ ->
let rec aux (t:term) : T.Tac term =
match t.t with
| Tm_Emp
| Tm_VProp
| Tm_Inames
| Tm_EmpInames
| Tm_Inames
| Tm_Unknown -> t
| Tm_Inv i ->
{ t with t = Tm_Inv (aux i) }
| Tm_AddInv i is ->
{ t with t = Tm_AddInv (aux i) (aux is) }
| Tm_Pure p -> { t with t = Tm_Pure (aux p) }
| Tm_Star l r -> { t with t = Tm_Star (aux l) (aux r) }
| Tm_ExistsSL u b body -> { t with t = Tm_ExistsSL u { b with binder_ty=aux b.binder_ty} (aux body) }
| Tm_ForallSL u b body -> { t with t = Tm_ForallSL u { b with binder_ty=aux b.binder_ty} (aux body) }
| Tm_FStar h ->
let h = FStar.Tactics.Visit.visit_tm visitor h in
assume (is_host_term h);
{ t with t=Tm_FStar h }
in
aux t
let visit_and_rewrite_conjuncts (p: (R.term & R.term)) (tms:list term) : T.Tac (list term) =
T.map (visit_and_rewrite p) tms
let visit_and_rewrite_conjuncts_all (p: list (R.term & R.term)) (goal:term) : T.Tac (term & term) =
let tms = Pulse.Typing.Combinators.vprop_as_list goal in
let tms' = T.fold_left (fun tms p -> visit_and_rewrite_conjuncts p tms) tms p in
assume (L.length tms' == L.length tms);
let lhs, rhs =
T.fold_left2
(fun (lhs, rhs) t t' ->
if eq_tm t t' then lhs, rhs
else (t::lhs, t'::rhs))
([], [])
tms tms'
in
Pulse.Typing.Combinators.list_as_vprop lhs,
Pulse.Typing.Combinators.list_as_vprop rhs
let disjoint (dom:list var) (cod:Set.set var) =
L.for_all (fun d -> not (Set.mem d cod)) dom
let rec as_subst (p : list (term & term))
(out:list subst_elt)
(domain:list var)
(codomain:Set.set var)
: option (list subst_elt) =
match p with
| [] ->
if disjoint domain codomain
then Some out
else None
| (e1, e2)::p -> (
match e1.t with
| Tm_FStar e1 -> (
match R.inspect_ln e1 with
| R.Tv_Var n -> (
let nv = R.inspect_namedv n in
as_subst p
(NT nv.uniq e2::out)
(nv.uniq ::domain )
(Set.union codomain (freevars e2))
)
| _ -> None
)
| _ -> None
) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Show.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Elaborate.Pure.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Visit.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.AssertWithBinders.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Show",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Env",
"short_module": "Env"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover",
"short_module": "Prover"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Naming",
"short_module": "N"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Pure",
"short_module": "PC"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Env",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"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": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"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: Prims.list (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) ->
t: Pulse.Syntax.Base.term
-> FStar.Tactics.Effect.Tac (Pulse.Syntax.Base.term * Pulse.Syntax.Base.term) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.term",
"Pulse.Checker.AssertWithBinders.as_subst",
"Prims.Nil",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Base.var",
"FStar.Set.empty",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Naming.subst_term",
"FStar.Pervasives.Native.option",
"Prims.unit",
"Pulse.Checker.AssertWithBinders.debug_log",
"Prims.string",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.term_to_string",
"Pulse.Checker.AssertWithBinders.visit_and_rewrite_conjuncts_all",
"FStar.Stubs.Reflection.Types.term",
"FStar.Tactics.Util.map",
"Pulse.Elaborate.Pure.elab_term",
"FStar.Pervasives.Native.fst",
"Pulse.Checker.Pure.instantiate_term_implicits"
] | [] | false | true | false | false | false | let rewrite_all (g: env) (p: list (term & term)) (t: term) : T.Tac (term & term) =
| match as_subst p [] [] Set.empty with
| Some s -> t, subst_term t s
| _ ->
let p:list (R.term & R.term) =
T.map (fun (e1, e2) ->
elab_term (fst (Pulse.Checker.Pure.instantiate_term_implicits g e1)),
elab_term (fst (Pulse.Checker.Pure.instantiate_term_implicits g e2)))
p
in
let lhs, rhs = visit_and_rewrite_conjuncts_all p t in
debug_log g
(fun _ -> Printf.sprintf "Rewrote %s to %s" (P.term_to_string lhs) (P.term_to_string rhs));
lhs, rhs | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.witness | val witness (t: term) : Tac unit | val witness (t: term) : Tac unit | let witness (t : term) : Tac unit =
apply_raw (`__witness);
exact t | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 270,
"start_col": 0,
"start_line": 268
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end
let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ())
private val __witness : (#a:Type) -> (x:a) -> (#p:(a -> Type)) -> squash (p x) -> squash (exists (x:a). p x)
private let __witness #a x #p _ = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.exact",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_raw"
] | [] | false | true | false | false | false | let witness (t: term) : Tac unit =
| apply_raw (`__witness);
exact t | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.and_elim | val and_elim (t: term) : Tac unit | val and_elim (t: term) : Tac unit | let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 7,
"end_line": 259,
"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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.try_with",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma",
"Prims.exn"
] | [] | false | true | false | false | false | let and_elim (t: term) : Tac unit =
| try apply_lemma (`(__and_elim (`#t))) with | _ -> apply_lemma (`(__and_elim' (`#t))) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.destruct_and | val destruct_and (t: term) : Tac (binding * binding) | val destruct_and (t: term) : Tac (binding * binding) | let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ()) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 263,
"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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 | t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac (FStar.Tactics.NamedView.binding * FStar.Tactics.NamedView.binding) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.NamedView.binding",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.Logic.implies_intro",
"Prims.unit",
"FStar.Tactics.V2.Logic.and_elim"
] | [] | false | true | false | false | false | let destruct_and (t: term) : Tac (binding * binding) =
| and_elim t;
(implies_intro (), implies_intro ()) | false |
FStar.Tactics.V2.Logic.fst | FStar.Tactics.V2.Logic.imp_intro_lem | val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b) | val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b) | let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f)) | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 113,
"end_line": 76,
"start_col": 0,
"start_line": 75
} | (*
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.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V2.Builtins.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"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 -> Prims.squash b) -> FStar.Pervasives.Lemma (ensures a ==> b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.squash",
"FStar.Classical.give_witness",
"Prims.l_imp",
"FStar.Classical.arrow_to_impl",
"FStar.Squash.bind_squash",
"Prims.unit"
] | [] | false | false | true | false | false | let imp_intro_lem #a #b f =
| FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x: squash a) ->
FStar.Squash.bind_squash x f)) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.