effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_get_top_index #t =
match t with
| U32 -> bn_get_top_index_u32
| U64 -> bn_get_top_index_u64 | val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len
let bn_get_top_index #t = | false | null | false | match t with
| U32 -> bn_get_top_index_u32
| U64 -> bn_get_top_index_u64 | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Lib.bn_get_top_index_u32",
"Hacl.Bignum.Lib.bn_get_top_index_u64",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Lib.bn_get_top_index_st"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
)
inline_for_extraction noextract
let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) =
b:lbignum t len ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.bn_get_top_index (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
let mk_bn_get_top_index #t len b =
push_frame ();
let priv = create 1ul (uint #t 0) in
let h0 = ST.get () in
[@ inline_let]
let refl h i = v (LSeq.index (as_seq h priv) 0) in
[@ inline_let]
let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in
[@ inline_let]
let inv h (i:nat{i <= v len}) =
modifies1 priv h0 h /\
live h priv /\ live h b /\ disjoint priv b /\
refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in
Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0);
Lib.Loops.for 0ul len inv
(fun i ->
Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i);
let mask = eq_mask b.(i) (zeros t SEC) in
let h1 = ST.get () in
priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i);
mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i));
let res = priv.(0ul) in
pop_frame ();
res
let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len
let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len
inline_for_extraction noextract
val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len | [] | Hacl.Bignum.Lib.bn_get_top_index | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Hacl.Bignum.Lib.bn_get_top_index_st t len | {
"end_col": 31,
"end_line": 145,
"start_col": 2,
"start_line": 143
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) =
b:lbignum t len ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.bn_get_top_index (as_seq h0 b)) | let bn_get_top_index_st (t: limb_t) (len: size_t{0 < v len}) = | false | null | false | b: lbignum t len
-> Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Prims.l_and",
"Lib.Buffer.modifies0",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.Lib.bn_get_top_index",
"Lib.Buffer.as_seq"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
)
inline_for_extraction noextract | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_get_top_index_st : t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Type0 | [] | Hacl.Bignum.Lib.bn_get_top_index_st | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Type0 | {
"end_col": 44,
"end_line": 102,
"start_col": 2,
"start_line": 98
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_get_bits_st (t:limb_t) =
len:size_t
-> b:lbignum t len
-> i:size_t
-> l:size_t{v l < bits t /\ v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits (as_seq h0 b) (v i) (v l)) | let bn_get_bits_st (t: limb_t) = | false | null | false | len: size_t -> b: lbignum t len -> i: size_t -> l: size_t{v l < bits t /\ v i / bits t < v len}
-> Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l)) | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Prims.op_Division",
"Hacl.Bignum.Definitions.limb",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Prims.eq2",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Lib.bn_get_bits",
"Lib.Buffer.as_seq"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
)
inline_for_extraction noextract
let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) =
b:lbignum t len ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.bn_get_top_index (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
let mk_bn_get_top_index #t len b =
push_frame ();
let priv = create 1ul (uint #t 0) in
let h0 = ST.get () in
[@ inline_let]
let refl h i = v (LSeq.index (as_seq h priv) 0) in
[@ inline_let]
let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in
[@ inline_let]
let inv h (i:nat{i <= v len}) =
modifies1 priv h0 h /\
live h priv /\ live h b /\ disjoint priv b /\
refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in
Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0);
Lib.Loops.for 0ul len inv
(fun i ->
Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i);
let mask = eq_mask b.(i) (zeros t SEC) in
let h1 = ST.get () in
priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i);
mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i));
let res = priv.(0ul) in
pop_frame ();
res
let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len
let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len
inline_for_extraction noextract
val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len
let bn_get_top_index #t =
match t with
| U32 -> bn_get_top_index_u32
| U64 -> bn_get_top_index_u64
inline_for_extraction noextract
val bn_get_bits_limb:
#t:limb_t
-> len:size_t
-> n:lbignum t len
-> ind:size_t{v ind / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h n)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits_limb (as_seq h0 n) (v ind))
let bn_get_bits_limb #t len n ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let p1 = n.(i) >>. j in
if i +! 1ul <. len && 0ul <. j then
p1 |. (n.(i +! 1ul) <<. (pbits -! j))
else
p1
inline_for_extraction noextract | false | true | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_get_bits_st : t: Hacl.Bignum.Definitions.limb_t -> Type0 | [] | Hacl.Bignum.Lib.bn_get_bits_st | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> Type0 | {
"end_col": 49,
"end_line": 182,
"start_col": 4,
"start_line": 175
} |
|
Prims.Tot | val bn_get_bits: #t:_ -> bn_get_bits_st t | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_get_bits #t =
match t with
| U32 -> bn_get_bits_u32
| U64 -> bn_get_bits_u64 | val bn_get_bits: #t:_ -> bn_get_bits_st t
let bn_get_bits #t = | false | null | false | match t with
| U32 -> bn_get_bits_u32
| U64 -> bn_get_bits_u64 | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Lib.bn_get_bits_u32",
"Hacl.Bignum.Lib.bn_get_bits_u64",
"Hacl.Bignum.Lib.bn_get_bits_st"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
)
inline_for_extraction noextract
let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) =
b:lbignum t len ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.bn_get_top_index (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
let mk_bn_get_top_index #t len b =
push_frame ();
let priv = create 1ul (uint #t 0) in
let h0 = ST.get () in
[@ inline_let]
let refl h i = v (LSeq.index (as_seq h priv) 0) in
[@ inline_let]
let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in
[@ inline_let]
let inv h (i:nat{i <= v len}) =
modifies1 priv h0 h /\
live h priv /\ live h b /\ disjoint priv b /\
refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in
Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0);
Lib.Loops.for 0ul len inv
(fun i ->
Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i);
let mask = eq_mask b.(i) (zeros t SEC) in
let h1 = ST.get () in
priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i);
mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i));
let res = priv.(0ul) in
pop_frame ();
res
let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len
let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len
inline_for_extraction noextract
val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len
let bn_get_top_index #t =
match t with
| U32 -> bn_get_top_index_u32
| U64 -> bn_get_top_index_u64
inline_for_extraction noextract
val bn_get_bits_limb:
#t:limb_t
-> len:size_t
-> n:lbignum t len
-> ind:size_t{v ind / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h n)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits_limb (as_seq h0 n) (v ind))
let bn_get_bits_limb #t len n ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let p1 = n.(i) >>. j in
if i +! 1ul <. len && 0ul <. j then
p1 |. (n.(i +! 1ul) <<. (pbits -! j))
else
p1
inline_for_extraction noextract
let bn_get_bits_st (t:limb_t) =
len:size_t
-> b:lbignum t len
-> i:size_t
-> l:size_t{v l < bits t /\ v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits (as_seq h0 b) (v i) (v l))
inline_for_extraction noextract
val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t
let mk_bn_get_bits #t len b i l =
[@inline_let] let mask_l = (uint #t #SEC 1 <<. l) -. uint #t 1 in
bn_get_bits_limb len b i &. mask_l
[@CInline]
let bn_get_bits_u32: bn_get_bits_st U32 = mk_bn_get_bits
[@CInline]
let bn_get_bits_u64: bn_get_bits_st U64 = mk_bn_get_bits
inline_for_extraction noextract
val bn_get_bits: #t:_ -> bn_get_bits_st t | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_get_bits: #t:_ -> bn_get_bits_st t | [] | Hacl.Bignum.Lib.bn_get_bits | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Bignum.Lib.bn_get_bits_st t | {
"end_col": 26,
"end_line": 202,
"start_col": 2,
"start_line": 200
} |
Prims.Tot | val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_bn_get_bits #t len b i l =
[@inline_let] let mask_l = (uint #t #SEC 1 <<. l) -. uint #t 1 in
bn_get_bits_limb len b i &. mask_l | val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t
let mk_bn_get_bits #t len b i l = | false | null | false | [@@ inline_let ]let mask_l = (uint #t #SEC 1 <<. l) -. uint #t 1 in
bn_get_bits_limb len b i &. mask_l | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Prims.op_Division",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.SEC",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.int_t",
"Hacl.Bignum.Lib.bn_get_bits_limb",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.uint"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
)
inline_for_extraction noextract
let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) =
b:lbignum t len ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.bn_get_top_index (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
let mk_bn_get_top_index #t len b =
push_frame ();
let priv = create 1ul (uint #t 0) in
let h0 = ST.get () in
[@ inline_let]
let refl h i = v (LSeq.index (as_seq h priv) 0) in
[@ inline_let]
let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in
[@ inline_let]
let inv h (i:nat{i <= v len}) =
modifies1 priv h0 h /\
live h priv /\ live h b /\ disjoint priv b /\
refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in
Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0);
Lib.Loops.for 0ul len inv
(fun i ->
Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i);
let mask = eq_mask b.(i) (zeros t SEC) in
let h1 = ST.get () in
priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i);
mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i));
let res = priv.(0ul) in
pop_frame ();
res
let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len
let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len
inline_for_extraction noextract
val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len
let bn_get_top_index #t =
match t with
| U32 -> bn_get_top_index_u32
| U64 -> bn_get_top_index_u64
inline_for_extraction noextract
val bn_get_bits_limb:
#t:limb_t
-> len:size_t
-> n:lbignum t len
-> ind:size_t{v ind / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h n)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits_limb (as_seq h0 n) (v ind))
let bn_get_bits_limb #t len n ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let p1 = n.(i) >>. j in
if i +! 1ul <. len && 0ul <. j then
p1 |. (n.(i +! 1ul) <<. (pbits -! j))
else
p1
inline_for_extraction noextract
let bn_get_bits_st (t:limb_t) =
len:size_t
-> b:lbignum t len
-> i:size_t
-> l:size_t{v l < bits t /\ v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits (as_seq h0 b) (v i) (v l))
inline_for_extraction noextract
val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t | [] | Hacl.Bignum.Lib.mk_bn_get_bits | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Bignum.Lib.bn_get_bits_st t | {
"end_col": 36,
"end_line": 189,
"start_col": 2,
"start_line": 188
} |
FStar.HyperStack.ST.Stack | val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
) | val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 = | true | null | false | [@@ inline_let ]let mask = uint #t 0 -. bit in
[@@ inline_let ]let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0
len
b1
b2
spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy) | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Definitions.lbignum",
"Lib.Buffer.loop2",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.op_Array_Assignment",
"Prims.unit",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Lib.IntTypes.op_Amp_Dot",
"Lib.LoopCombinators.unfold_repeati",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Buffer.as_seq",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.nat",
"Hacl.Spec.Bignum.Lib.cswap2_f",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.uint"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) | [] | Hacl.Bignum.Lib.cswap2_st | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t ->
bit: Hacl.Bignum.Definitions.limb t ->
b1: Hacl.Bignum.Definitions.lbignum t len ->
b2: Hacl.Bignum.Definitions.lbignum t len
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 3,
"end_line": 93,
"start_col": 2,
"start_line": 81
} |
FStar.HyperStack.ST.Stack | val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j) | val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind = | true | null | false | [@@ inline_let ]let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j) | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Lib.Buffer.op_Array_Assignment",
"Hacl.Bignum.Definitions.limb",
"Prims.unit",
"Lib.IntTypes.op_Bar_Dot",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.uint",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Lib.IntTypes.op_Percent_Dot",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.size"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) | [] | Hacl.Bignum.Lib.bn_set_ith_bit | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t ->
b: Hacl.Bignum.Definitions.lbignum t len ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i / Lib.IntTypes.bits t < Lib.IntTypes.v len}
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 45,
"end_line": 65,
"start_col": 2,
"start_line": 59
} |
FStar.HyperStack.ST.Stack | val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i)) | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1 | val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind = | true | null | false | [@@ inline_let ]let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1 | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Lib.IntTypes.uint",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Percent_Dot",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.size"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i)) | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i)) | [] | Hacl.Bignum.Lib.bn_get_ith_bit | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t ->
b: Hacl.Bignum.Definitions.lbignum t len ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i / Lib.IntTypes.bits t < Lib.IntTypes.v len}
-> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t) | {
"end_col": 26,
"end_line": 44,
"start_col": 2,
"start_line": 37
} |
FStar.HyperStack.ST.Stack | val bn_get_bits_limb:
#t:limb_t
-> len:size_t
-> n:lbignum t len
-> ind:size_t{v ind / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h n)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits_limb (as_seq h0 n) (v ind)) | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_get_bits_limb #t len n ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let p1 = n.(i) >>. j in
if i +! 1ul <. len && 0ul <. j then
p1 |. (n.(i +! 1ul) <<. (pbits -! j))
else
p1 | val bn_get_bits_limb:
#t:limb_t
-> len:size_t
-> n:lbignum t len
-> ind:size_t{v ind / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h n)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits_limb (as_seq h0 n) (v ind))
let bn_get_bits_limb #t len n ind = | true | null | false | [@@ inline_let ]let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let p1 = n.(i) >>. j in
if i +! 1ul <. len && 0ul <. j then p1 |. (n.(i +! 1ul) <<. (pbits -! j)) else p1 | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Prims.op_AmpAmp",
"Lib.IntTypes.op_Less_Dot",
"Lib.IntTypes.op_Plus_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Bar_Dot",
"Lib.IntTypes.SEC",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.op_Subtraction_Bang",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"Prims.bool",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Lib.IntTypes.op_Percent_Dot",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.size"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
)
inline_for_extraction noextract
let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) =
b:lbignum t len ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.bn_get_top_index (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
let mk_bn_get_top_index #t len b =
push_frame ();
let priv = create 1ul (uint #t 0) in
let h0 = ST.get () in
[@ inline_let]
let refl h i = v (LSeq.index (as_seq h priv) 0) in
[@ inline_let]
let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in
[@ inline_let]
let inv h (i:nat{i <= v len}) =
modifies1 priv h0 h /\
live h priv /\ live h b /\ disjoint priv b /\
refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in
Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0);
Lib.Loops.for 0ul len inv
(fun i ->
Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i);
let mask = eq_mask b.(i) (zeros t SEC) in
let h1 = ST.get () in
priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i);
mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i));
let res = priv.(0ul) in
pop_frame ();
res
let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len
let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len
inline_for_extraction noextract
val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len
let bn_get_top_index #t =
match t with
| U32 -> bn_get_top_index_u32
| U64 -> bn_get_top_index_u64
inline_for_extraction noextract
val bn_get_bits_limb:
#t:limb_t
-> len:size_t
-> n:lbignum t len
-> ind:size_t{v ind / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h n)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits_limb (as_seq h0 n) (v ind)) | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_get_bits_limb:
#t:limb_t
-> len:size_t
-> n:lbignum t len
-> ind:size_t{v ind / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h n)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_bits_limb (as_seq h0 n) (v ind)) | [] | Hacl.Bignum.Lib.bn_get_bits_limb | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Lib.IntTypes.size_t ->
n: Hacl.Bignum.Definitions.lbignum t len ->
ind: Lib.IntTypes.size_t{Lib.IntTypes.v ind / Lib.IntTypes.bits t < Lib.IntTypes.v len}
-> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t) | {
"end_col": 6,
"end_line": 170,
"start_col": 2,
"start_line": 160
} |
Prims.Tot | val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mk_bn_get_top_index #t len b =
push_frame ();
let priv = create 1ul (uint #t 0) in
let h0 = ST.get () in
[@ inline_let]
let refl h i = v (LSeq.index (as_seq h priv) 0) in
[@ inline_let]
let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in
[@ inline_let]
let inv h (i:nat{i <= v len}) =
modifies1 priv h0 h /\
live h priv /\ live h b /\ disjoint priv b /\
refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in
Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0);
Lib.Loops.for 0ul len inv
(fun i ->
Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i);
let mask = eq_mask b.(i) (zeros t SEC) in
let h1 = ST.get () in
priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i);
mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i));
let res = priv.(0ul) in
pop_frame ();
res | val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
let mk_bn_get_top_index #t len b = | false | null | false | push_frame ();
let priv = create 1ul (uint #t 0) in
let h0 = ST.get () in
[@@ inline_let ]let refl h i = v (LSeq.index (as_seq h priv) 0) in
[@@ inline_let ]let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in
[@@ inline_let ]let inv h (i: nat{i <= v len}) =
modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\
refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0)
in
Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0);
Lib.Loops.for 0ul
len
inv
(fun i ->
Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i);
let mask = eq_mask b.(i) (zeros t SEC) in
let h1 = ST.get () in
priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i);
mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i));
let res = priv.(0ul) in
pop_frame ();
res | {
"checked_file": "Hacl.Bignum.Lib.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.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.Bignum.Lib.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"FStar.UInt32.__uint_to_t",
"Lib.Loops.for",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Base.mask_select_lemma",
"Lib.Sequence.index",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.Base.size_to_limb",
"Lib.Buffer.op_Array_Assignment",
"Hacl.Spec.Bignum.Base.mask_select",
"Hacl.Spec.Bignum.Definitions.limb",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.IntTypes.eq_mask",
"Lib.IntTypes.zeros",
"Lib.LoopCombinators.unfold_repeat_gen",
"Hacl.Spec.Bignum.Lib.bn_get_top_index_t",
"Lib.LoopCombinators.eq_repeat_gen0",
"Prims.nat",
"Prims.logical",
"Lib.Buffer.modifies1",
"Lib.Buffer.live",
"Lib.Buffer.disjoint",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.LoopCombinators.repeat_gen",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Lib.bn_get_top_index_f",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.uint",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
)
inline_for_extraction noextract
let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) =
b:lbignum t len ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.bn_get_top_index (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len | false | false | Hacl.Bignum.Lib.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len | [] | Hacl.Bignum.Lib.mk_bn_get_top_index | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Hacl.Bignum.Lib.bn_get_top_index_st t len | {
"end_col": 5,
"end_line": 133,
"start_col": 2,
"start_line": 108
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) | let vale_p = | false | null | false | let open Vale.X64.CPU_Features_s in adx_enabled /\ bmi2_enabled | {
"checked_file": "Hacl.HPKE.Curve64_CP256_SHA256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"Spec.Agile.DH.fst.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"Hacl.Impl.HPKE.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Curve64_CP256_SHA256.fsti"
} | [
"total"
] | [
"Prims.l_and",
"Prims.b2t",
"Vale.X64.CPU_Features_s.adx_enabled",
"Vale.X64.CPU_Features_s.bmi2_enabled"
] | [] | module Hacl.HPKE.Curve64_CP256_SHA256
open Hacl.Impl.HPKE
module S = Spec.Agile.HPKE
module DH = Spec.Agile.DH
module AEAD = Spec.Agile.AEAD
module Hash = Spec.Agile.Hash
noextract unfold
let cs:S.ciphersuite = (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256) | false | true | Hacl.HPKE.Curve64_CP256_SHA256.fsti | {
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val vale_p : Prims.logical | [] | Hacl.HPKE.Curve64_CP256_SHA256.vale_p | {
"file_name": "code/hpke/Hacl.HPKE.Curve64_CP256_SHA256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.logical | {
"end_col": 65,
"end_line": 13,
"start_col": 38,
"start_line": 13
} |
|
Prims.Tot | val cs:S.ciphersuite | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cs:S.ciphersuite = (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256) | val cs:S.ciphersuite
let cs:S.ciphersuite = | false | null | false | (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256) | {
"checked_file": "Hacl.HPKE.Curve64_CP256_SHA256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.Hash.fsti.checked",
"Spec.Agile.DH.fst.checked",
"Spec.Agile.AEAD.fsti.checked",
"prims.fst.checked",
"Hacl.Impl.HPKE.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Curve64_CP256_SHA256.fsti"
} | [
"total"
] | [
"FStar.Pervasives.Native.Mktuple4",
"Spec.Agile.DH.algorithm",
"Spec.Agile.HPKE.hash_algorithm",
"Spec.Agile.HPKE.aead",
"Spec.Hash.Definitions.hash_alg",
"Spec.Agile.DH.DH_Curve25519",
"Spec.Hash.Definitions.SHA2_256",
"Spec.Agile.HPKE.Seal",
"Spec.Agile.AEAD.CHACHA20_POLY1305"
] | [] | module Hacl.HPKE.Curve64_CP256_SHA256
open Hacl.Impl.HPKE
module S = Spec.Agile.HPKE
module DH = Spec.Agile.DH
module AEAD = Spec.Agile.AEAD
module Hash = Spec.Agile.Hash | false | true | Hacl.HPKE.Curve64_CP256_SHA256.fsti | {
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cs:S.ciphersuite | [] | Hacl.HPKE.Curve64_CP256_SHA256.cs | {
"file_name": "code/hpke/Hacl.HPKE.Curve64_CP256_SHA256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Spec.Agile.HPKE.ciphersuite | {
"end_col": 102,
"end_line": 10,
"start_col": 23,
"start_line": 10
} |
Prims.Tot | val unsquash_well_founded (#a:Type u#a) (r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r))
: well_founded u#a u#r r | [
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let unsquash_well_founded (#a:Type u#a) (r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r))
: well_founded u#a u#r r
= let rec f (x:a)
: Tot (acc r x)
(decreases {:well-founded (lift_binrel_squashed_as_well_founded_relation wf_r) (| a, x |)})
= AccIntro (let g_smaller (y: a) (u: r y x) : acc r y =
lift_binrel_squashed_intro wf_r y x (FStar.Squash.return_squash u);
f y
in g_smaller)
in
f | val unsquash_well_founded (#a:Type u#a) (r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r))
: well_founded u#a u#r r
let unsquash_well_founded
(#a: Type u#a)
(r: binrel u#a u#r a)
(wf_r: well_founded (squash_binrel r))
: well_founded u#a u#r r = | false | null | false | let rec f (x: a)
: Tot (acc r x)
(decreases {:well-founded (lift_binrel_squashed_as_well_founded_relation wf_r) (| a, x |) }) =
AccIntro
(let g_smaller (y: a) (u: r y x) : acc r y =
lift_binrel_squashed_intro wf_r y x (FStar.Squash.return_squash u);
f y
in
g_smaller)
in
f | {
"checked_file": "FStar.WellFounded.Util.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.WellFounded.Util.fst"
} | [
"total"
] | [
"FStar.WellFounded.binrel",
"FStar.WellFounded.well_founded",
"FStar.WellFounded.Util.squash_binrel",
"FStar.WellFounded.acc",
"FStar.WellFounded.Util.lift_binrel_squashed_as_well_founded_relation",
"Prims.Mkdtuple2",
"FStar.WellFounded.AccIntro",
"Prims.unit",
"FStar.WellFounded.Util.lift_binrel_squashed_intro",
"FStar.Squash.return_squash"
] | [] | module FStar.WellFounded.Util
open FStar.WellFounded
#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
= let t0 : top = (| a, y |) in
let t1 : top = (| a, x |) in
let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in
let pf : squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
()
let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x)
= let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in
let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) ->
let p1 : (dfst y == a /\ a == a) = dfst pf in
let p2 : r (dsnd y) x = dsnd pf in
introduce dfst y == a /\ r (dsnd y) x
with eliminate dfst y == a /\ a == a
returns _
with l r. l
and FStar.Squash.return_squash p2)
in
()
let lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y)
= dsnd p
let lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r)
: well_founded (lift_binrel r)
= let rec aux (y:top{dfst y == a})
(pf:acc r (dsnd y))
: Tot (acc (lift_binrel r) y)
(decreases pf)
= AccIntro (fun (z:top) (p:lift_binrel r z y) ->
aux z (pf.access_smaller (dsnd z) (lower_binrel z y p)))
in
let aux' (y:top{dfst y =!= a})
: acc (lift_binrel r) y
= AccIntro (fun y p -> false_elim ())
in
fun (x:top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b
then aux x (wf_r (dsnd x))
else aux' x
let lower_binrel_squashed (#a:Type u#a)
(#r:binrel u#a u#r a)
(x y:top u#a)
(p:lift_binrel_squashed r x y)
: squash (r (dsnd x) (dsnd y))
= assert (dfst x==a /\ dfst y==a /\ squash (r (dsnd x) (dsnd y)))
by FStar.Tactics.(exact (quote (FStar.Squash.return_squash p)))
let lift_binrel_squashed_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded (squash_binrel r))
: well_founded (lift_binrel_squashed r)
= let rec aux (y:top{dfst y == a})
(pf:acc (squash_binrel r) (dsnd y))
: Tot (acc (lift_binrel_squashed r) y)
(decreases pf)
= AccIntro (fun (z:top) (p:lift_binrel_squashed r z y) ->
let p = lower_binrel_squashed z y p in
aux z (pf.access_smaller (dsnd z) (FStar.Squash.join_squash p)))
in
let aux' (y:top{dfst y =!= a})
: acc (lift_binrel_squashed r) y
= AccIntro (fun y p -> false_elim ())
in
fun (x:top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b
then aux x (wf_r (dsnd x))
else aux' x
let lift_binrel_squashed_intro (#a:Type) (#r:binrel a)
(wf_r:well_founded (squash_binrel r))
(x y:a)
(sqr:squash (r x y))
: Lemma
(ensures lift_binrel_squashed r (|a, x|) (|a, y|))
= assert (lift_binrel_squashed r (| a, x |) (| a , y |))
by FStar.Tactics.(
norm [delta_only [`%lift_binrel_squashed]];
split(); split(); trefl(); trefl();
mapply (`FStar.Squash.join_squash)
)
let unsquash_well_founded (#a:Type u#a) (r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) | false | false | FStar.WellFounded.Util.fst | {
"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"
} | null | val unsquash_well_founded (#a:Type u#a) (r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r))
: well_founded u#a u#r r | [] | FStar.WellFounded.Util.unsquash_well_founded | {
"file_name": "ulib/FStar.WellFounded.Util.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
r: FStar.WellFounded.binrel a ->
wf_r: FStar.WellFounded.well_founded (FStar.WellFounded.Util.squash_binrel r)
-> FStar.WellFounded.well_founded r | {
"end_col": 5,
"end_line": 121,
"start_col": 3,
"start_line": 113
} |
FStar.Pervasives.Lemma | val intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |)) | [
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
= let t0 : top = (| a, y |) in
let t1 : top = (| a, x |) in
let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in
let pf : squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
() | val intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
let intro_lift_binrel (#a: Type) (r: binrel a) (y x: a)
: Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = | false | null | true | let t0:top = (| a, y |) in
let t1:top = (| a, x |) in
let pf1:squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2:squash (r (dsnd t0) (dsnd t1)) = () in
let pf:squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1
(fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2
(fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p:lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
() | {
"checked_file": "FStar.WellFounded.Util.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.WellFounded.Util.fst"
} | [
"lemma"
] | [
"FStar.WellFounded.binrel",
"Prims.squash",
"FStar.WellFounded.Util.lift_binrel",
"FStar.Squash.bind_squash",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.dfst",
"FStar.Pervasives.dsnd",
"FStar.Squash.return_squash",
"Prims.Mkdtuple2",
"FStar.WellFounded.Util.top",
"Prims.unit",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module FStar.WellFounded.Util
open FStar.WellFounded
#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x) | false | false | FStar.WellFounded.Util.fst | {
"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"
} | null | val intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |)) | [] | FStar.WellFounded.Util.intro_lift_binrel | {
"file_name": "ulib/FStar.WellFounded.Util.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r: FStar.WellFounded.binrel a -> y: a -> x: a
-> FStar.Pervasives.Lemma (requires r y x)
(ensures FStar.WellFounded.Util.lift_binrel r (| a, y |) (| a, x |)) | {
"end_col": 6,
"end_line": 20,
"start_col": 3,
"start_line": 10
} |
Prims.Tot | val lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r)
: well_founded (lift_binrel r) | [
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r)
: well_founded (lift_binrel r)
= let rec aux (y:top{dfst y == a})
(pf:acc r (dsnd y))
: Tot (acc (lift_binrel r) y)
(decreases pf)
= AccIntro (fun (z:top) (p:lift_binrel r z y) ->
aux z (pf.access_smaller (dsnd z) (lower_binrel z y p)))
in
let aux' (y:top{dfst y =!= a})
: acc (lift_binrel r) y
= AccIntro (fun y p -> false_elim ())
in
fun (x:top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b
then aux x (wf_r (dsnd x))
else aux' x | val lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r)
: well_founded (lift_binrel r)
let lift_binrel_well_founded (#a: Type u#a) (#r: binrel u#a u#r a) (wf_r: well_founded r)
: well_founded (lift_binrel r) = | false | null | false | let rec aux (y: top{dfst y == a}) (pf: acc r (dsnd y)) : Tot (acc (lift_binrel r) y) (decreases pf)
=
AccIntro
(fun (z: top) (p: lift_binrel r z y) -> aux z (pf.access_smaller (dsnd z) (lower_binrel z y p)))
in
let aux' (y: top{dfst y =!= a}) : acc (lift_binrel r) y = AccIntro (fun y p -> false_elim ()) in
fun (x: top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b then aux x (wf_r (dsnd x)) else aux' x | {
"checked_file": "FStar.WellFounded.Util.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.WellFounded.Util.fst"
} | [
"total"
] | [
"FStar.WellFounded.binrel",
"FStar.WellFounded.well_founded",
"FStar.WellFounded.Util.top",
"FStar.Pervasives.dsnd",
"Prims.bool",
"FStar.WellFounded.acc",
"FStar.WellFounded.Util.lift_binrel",
"Prims.l_iff",
"Prims.b2t",
"Prims.op_Equality",
"Prims.eq2",
"FStar.Pervasives.dfst",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.l_not",
"FStar.WellFounded.AccIntro",
"FStar.Pervasives.false_elim",
"FStar.WellFounded.__proj__AccIntro__item__access_smaller",
"FStar.WellFounded.Util.lower_binrel"
] | [] | module FStar.WellFounded.Util
open FStar.WellFounded
#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
= let t0 : top = (| a, y |) in
let t1 : top = (| a, x |) in
let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in
let pf : squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
()
let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x)
= let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in
let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) ->
let p1 : (dfst y == a /\ a == a) = dfst pf in
let p2 : r (dsnd y) x = dsnd pf in
introduce dfst y == a /\ r (dsnd y) x
with eliminate dfst y == a /\ a == a
returns _
with l r. l
and FStar.Squash.return_squash p2)
in
()
let lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y)
= dsnd p
let lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r) | false | false | FStar.WellFounded.Util.fst | {
"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"
} | null | val lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r)
: well_founded (lift_binrel r) | [] | FStar.WellFounded.Util.lift_binrel_well_founded | {
"file_name": "ulib/FStar.WellFounded.Util.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | wf_r: FStar.WellFounded.well_founded r
-> FStar.WellFounded.well_founded (FStar.WellFounded.Util.lift_binrel r) | {
"end_col": 17,
"end_line": 65,
"start_col": 3,
"start_line": 50
} |
Prims.Tot | val lift_binrel_squashed_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded (squash_binrel r))
: well_founded (lift_binrel_squashed r) | [
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lift_binrel_squashed_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded (squash_binrel r))
: well_founded (lift_binrel_squashed r)
= let rec aux (y:top{dfst y == a})
(pf:acc (squash_binrel r) (dsnd y))
: Tot (acc (lift_binrel_squashed r) y)
(decreases pf)
= AccIntro (fun (z:top) (p:lift_binrel_squashed r z y) ->
let p = lower_binrel_squashed z y p in
aux z (pf.access_smaller (dsnd z) (FStar.Squash.join_squash p)))
in
let aux' (y:top{dfst y =!= a})
: acc (lift_binrel_squashed r) y
= AccIntro (fun y p -> false_elim ())
in
fun (x:top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b
then aux x (wf_r (dsnd x))
else aux' x | val lift_binrel_squashed_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded (squash_binrel r))
: well_founded (lift_binrel_squashed r)
let lift_binrel_squashed_well_founded
(#a: Type u#a)
(#r: binrel u#a u#r a)
(wf_r: well_founded (squash_binrel r))
: well_founded (lift_binrel_squashed r) = | false | null | false | let rec aux (y: top{dfst y == a}) (pf: acc (squash_binrel r) (dsnd y))
: Tot (acc (lift_binrel_squashed r) y) (decreases pf) =
AccIntro
(fun (z: top) (p: lift_binrel_squashed r z y) ->
let p = lower_binrel_squashed z y p in
aux z (pf.access_smaller (dsnd z) (FStar.Squash.join_squash p)))
in
let aux' (y: top{dfst y =!= a}) : acc (lift_binrel_squashed r) y =
AccIntro (fun y p -> false_elim ())
in
fun (x: top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b then aux x (wf_r (dsnd x)) else aux' x | {
"checked_file": "FStar.WellFounded.Util.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.WellFounded.Util.fst"
} | [
"total"
] | [
"FStar.WellFounded.binrel",
"FStar.WellFounded.well_founded",
"FStar.WellFounded.Util.squash_binrel",
"FStar.WellFounded.Util.top",
"FStar.Pervasives.dsnd",
"Prims.bool",
"FStar.WellFounded.acc",
"FStar.WellFounded.Util.lift_binrel_squashed",
"Prims.l_iff",
"Prims.b2t",
"Prims.op_Equality",
"Prims.eq2",
"FStar.Pervasives.dfst",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.l_not",
"FStar.WellFounded.AccIntro",
"FStar.Pervasives.false_elim",
"FStar.WellFounded.__proj__AccIntro__item__access_smaller",
"FStar.Squash.join_squash",
"Prims.squash",
"FStar.WellFounded.Util.lower_binrel_squashed"
] | [] | module FStar.WellFounded.Util
open FStar.WellFounded
#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
= let t0 : top = (| a, y |) in
let t1 : top = (| a, x |) in
let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in
let pf : squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
()
let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x)
= let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in
let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) ->
let p1 : (dfst y == a /\ a == a) = dfst pf in
let p2 : r (dsnd y) x = dsnd pf in
introduce dfst y == a /\ r (dsnd y) x
with eliminate dfst y == a /\ a == a
returns _
with l r. l
and FStar.Squash.return_squash p2)
in
()
let lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y)
= dsnd p
let lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r)
: well_founded (lift_binrel r)
= let rec aux (y:top{dfst y == a})
(pf:acc r (dsnd y))
: Tot (acc (lift_binrel r) y)
(decreases pf)
= AccIntro (fun (z:top) (p:lift_binrel r z y) ->
aux z (pf.access_smaller (dsnd z) (lower_binrel z y p)))
in
let aux' (y:top{dfst y =!= a})
: acc (lift_binrel r) y
= AccIntro (fun y p -> false_elim ())
in
fun (x:top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b
then aux x (wf_r (dsnd x))
else aux' x
let lower_binrel_squashed (#a:Type u#a)
(#r:binrel u#a u#r a)
(x y:top u#a)
(p:lift_binrel_squashed r x y)
: squash (r (dsnd x) (dsnd y))
= assert (dfst x==a /\ dfst y==a /\ squash (r (dsnd x) (dsnd y)))
by FStar.Tactics.(exact (quote (FStar.Squash.return_squash p)))
let lift_binrel_squashed_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded (squash_binrel r)) | false | false | FStar.WellFounded.Util.fst | {
"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"
} | null | val lift_binrel_squashed_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded (squash_binrel r))
: well_founded (lift_binrel_squashed r) | [] | FStar.WellFounded.Util.lift_binrel_squashed_well_founded | {
"file_name": "ulib/FStar.WellFounded.Util.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | wf_r: FStar.WellFounded.well_founded (FStar.WellFounded.Util.squash_binrel r)
-> FStar.WellFounded.well_founded (FStar.WellFounded.Util.lift_binrel_squashed r) | {
"end_col": 17,
"end_line": 96,
"start_col": 3,
"start_line": 80
} |
Prims.Tot | val lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y) | [
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y)
= dsnd p | val lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y)
let lower_binrel (#a: Type) (#r: binrel a) (x y: top) (p: lift_binrel r x y) : r (dsnd x) (dsnd y) = | false | null | false | dsnd p | {
"checked_file": "FStar.WellFounded.Util.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.WellFounded.Util.fst"
} | [
"total"
] | [
"FStar.WellFounded.binrel",
"FStar.WellFounded.Util.top",
"FStar.WellFounded.Util.lift_binrel",
"FStar.Pervasives.dsnd",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.dfst"
] | [] | module FStar.WellFounded.Util
open FStar.WellFounded
#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
= let t0 : top = (| a, y |) in
let t1 : top = (| a, x |) in
let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in
let pf : squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
()
let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x)
= let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in
let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) ->
let p1 : (dfst y == a /\ a == a) = dfst pf in
let p2 : r (dsnd y) x = dsnd pf in
introduce dfst y == a /\ r (dsnd y) x
with eliminate dfst y == a /\ a == a
returns _
with l r. l
and FStar.Squash.return_squash p2)
in
()
let lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y) | false | false | FStar.WellFounded.Util.fst | {
"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"
} | null | val lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y) | [] | FStar.WellFounded.Util.lower_binrel | {
"file_name": "ulib/FStar.WellFounded.Util.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
x: FStar.WellFounded.Util.top ->
y: FStar.WellFounded.Util.top ->
p: FStar.WellFounded.Util.lift_binrel r x y
-> r (FStar.Pervasives.dsnd x) (FStar.Pervasives.dsnd y) | {
"end_col": 10,
"end_line": 43,
"start_col": 4,
"start_line": 43
} |
FStar.Pervasives.Lemma | val lift_binrel_squashed_intro (#a:Type)
(#r:binrel a)
(wf_r:well_founded (squash_binrel r))
(x y:a)
(sqr:squash (r x y))
: Lemma
(ensures lift_binrel_squashed r (|a, x|) (|a, y|)) | [
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lift_binrel_squashed_intro (#a:Type) (#r:binrel a)
(wf_r:well_founded (squash_binrel r))
(x y:a)
(sqr:squash (r x y))
: Lemma
(ensures lift_binrel_squashed r (|a, x|) (|a, y|))
= assert (lift_binrel_squashed r (| a, x |) (| a , y |))
by FStar.Tactics.(
norm [delta_only [`%lift_binrel_squashed]];
split(); split(); trefl(); trefl();
mapply (`FStar.Squash.join_squash)
) | val lift_binrel_squashed_intro (#a:Type)
(#r:binrel a)
(wf_r:well_founded (squash_binrel r))
(x y:a)
(sqr:squash (r x y))
: Lemma
(ensures lift_binrel_squashed r (|a, x|) (|a, y|))
let lift_binrel_squashed_intro
(#a: Type)
(#r: binrel a)
(wf_r: well_founded (squash_binrel r))
(x y: a)
(sqr: squash (r x y))
: Lemma (ensures lift_binrel_squashed r (| a, x |) (| a, y |)) = | false | null | true | FStar.Tactics.Effect.assert_by_tactic (lift_binrel_squashed r (| a, x |) (| a, y |))
(fun _ ->
();
let open FStar.Tactics in
norm [delta_only [`%lift_binrel_squashed]];
split ();
split ();
trefl ();
trefl ();
mapply (`FStar.Squash.join_squash)) | {
"checked_file": "FStar.WellFounded.Util.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.WellFounded.Util.fst"
} | [
"lemma"
] | [
"FStar.WellFounded.binrel",
"FStar.WellFounded.well_founded",
"FStar.WellFounded.Util.squash_binrel",
"Prims.squash",
"FStar.Tactics.Effect.assert_by_tactic",
"FStar.WellFounded.Util.lift_binrel_squashed",
"Prims.Mkdtuple2",
"Prims.unit",
"FStar.Tactics.V1.Derived.mapply",
"FStar.Tactics.V1.Derived.trefl",
"FStar.Tactics.V1.Logic.split",
"FStar.Tactics.V1.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"Prims.string",
"Prims.Nil",
"Prims.l_True",
"FStar.Pervasives.pattern"
] | [] | module FStar.WellFounded.Util
open FStar.WellFounded
#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
= let t0 : top = (| a, y |) in
let t1 : top = (| a, x |) in
let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in
let pf : squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
()
let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x)
= let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in
let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) ->
let p1 : (dfst y == a /\ a == a) = dfst pf in
let p2 : r (dsnd y) x = dsnd pf in
introduce dfst y == a /\ r (dsnd y) x
with eliminate dfst y == a /\ a == a
returns _
with l r. l
and FStar.Squash.return_squash p2)
in
()
let lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y)
= dsnd p
let lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r)
: well_founded (lift_binrel r)
= let rec aux (y:top{dfst y == a})
(pf:acc r (dsnd y))
: Tot (acc (lift_binrel r) y)
(decreases pf)
= AccIntro (fun (z:top) (p:lift_binrel r z y) ->
aux z (pf.access_smaller (dsnd z) (lower_binrel z y p)))
in
let aux' (y:top{dfst y =!= a})
: acc (lift_binrel r) y
= AccIntro (fun y p -> false_elim ())
in
fun (x:top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b
then aux x (wf_r (dsnd x))
else aux' x
let lower_binrel_squashed (#a:Type u#a)
(#r:binrel u#a u#r a)
(x y:top u#a)
(p:lift_binrel_squashed r x y)
: squash (r (dsnd x) (dsnd y))
= assert (dfst x==a /\ dfst y==a /\ squash (r (dsnd x) (dsnd y)))
by FStar.Tactics.(exact (quote (FStar.Squash.return_squash p)))
let lift_binrel_squashed_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded (squash_binrel r))
: well_founded (lift_binrel_squashed r)
= let rec aux (y:top{dfst y == a})
(pf:acc (squash_binrel r) (dsnd y))
: Tot (acc (lift_binrel_squashed r) y)
(decreases pf)
= AccIntro (fun (z:top) (p:lift_binrel_squashed r z y) ->
let p = lower_binrel_squashed z y p in
aux z (pf.access_smaller (dsnd z) (FStar.Squash.join_squash p)))
in
let aux' (y:top{dfst y =!= a})
: acc (lift_binrel_squashed r) y
= AccIntro (fun y p -> false_elim ())
in
fun (x:top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b
then aux x (wf_r (dsnd x))
else aux' x
let lift_binrel_squashed_intro (#a:Type) (#r:binrel a)
(wf_r:well_founded (squash_binrel r))
(x y:a)
(sqr:squash (r x y))
: Lemma | false | false | FStar.WellFounded.Util.fst | {
"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"
} | null | val lift_binrel_squashed_intro (#a:Type)
(#r:binrel a)
(wf_r:well_founded (squash_binrel r))
(x y:a)
(sqr:squash (r x y))
: Lemma
(ensures lift_binrel_squashed r (|a, x|) (|a, y|)) | [] | FStar.WellFounded.Util.lift_binrel_squashed_intro | {
"file_name": "ulib/FStar.WellFounded.Util.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
wf_r: FStar.WellFounded.well_founded (FStar.WellFounded.Util.squash_binrel r) ->
x: a ->
y: a ->
sqr: Prims.squash (r x y)
-> FStar.Pervasives.Lemma
(ensures FStar.WellFounded.Util.lift_binrel_squashed r (| a, x |) (| a, y |)) | {
"end_col": 12,
"end_line": 109,
"start_col": 4,
"start_line": 104
} |
Prims.Tot | val lower_binrel_squashed (#a:Type u#a)
(#r:binrel u#a u#r a)
(x y:top u#a)
(p:lift_binrel_squashed r x y)
: squash (r (dsnd x) (dsnd y)) | [
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lower_binrel_squashed (#a:Type u#a)
(#r:binrel u#a u#r a)
(x y:top u#a)
(p:lift_binrel_squashed r x y)
: squash (r (dsnd x) (dsnd y))
= assert (dfst x==a /\ dfst y==a /\ squash (r (dsnd x) (dsnd y)))
by FStar.Tactics.(exact (quote (FStar.Squash.return_squash p))) | val lower_binrel_squashed (#a:Type u#a)
(#r:binrel u#a u#r a)
(x y:top u#a)
(p:lift_binrel_squashed r x y)
: squash (r (dsnd x) (dsnd y))
let lower_binrel_squashed
(#a: Type u#a)
(#r: binrel u#a u#r a)
(x y: top u#a)
(p: lift_binrel_squashed r x y)
: squash (r (dsnd x) (dsnd y)) = | false | null | true | FStar.Tactics.Effect.assert_by_tactic (dfst x == a /\ dfst y == a /\ squash (r (dsnd x) (dsnd y)))
(fun _ ->
();
let open FStar.Tactics in exact (quote (FStar.Squash.return_squash p))) | {
"checked_file": "FStar.WellFounded.Util.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.WellFounded.Util.fst"
} | [
"total"
] | [
"FStar.WellFounded.binrel",
"FStar.WellFounded.Util.top",
"FStar.WellFounded.Util.lift_binrel_squashed",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.dfst",
"Prims.squash",
"FStar.Pervasives.dsnd",
"Prims.unit",
"FStar.Tactics.V1.Derived.exact",
"FStar.Reflection.Types.term",
"FStar.Squash.return_squash"
] | [] | module FStar.WellFounded.Util
open FStar.WellFounded
#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
= let t0 : top = (| a, y |) in
let t1 : top = (| a, x |) in
let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in
let pf : squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
()
let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x)
= let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in
let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) ->
let p1 : (dfst y == a /\ a == a) = dfst pf in
let p2 : r (dsnd y) x = dsnd pf in
introduce dfst y == a /\ r (dsnd y) x
with eliminate dfst y == a /\ a == a
returns _
with l r. l
and FStar.Squash.return_squash p2)
in
()
let lower_binrel (#a:Type)
(#r:binrel a)
(x y:top)
(p:lift_binrel r x y)
: r (dsnd x) (dsnd y)
= dsnd p
let lift_binrel_well_founded (#a:Type u#a)
(#r:binrel u#a u#r a)
(wf_r:well_founded r)
: well_founded (lift_binrel r)
= let rec aux (y:top{dfst y == a})
(pf:acc r (dsnd y))
: Tot (acc (lift_binrel r) y)
(decreases pf)
= AccIntro (fun (z:top) (p:lift_binrel r z y) ->
aux z (pf.access_smaller (dsnd z) (lower_binrel z y p)))
in
let aux' (y:top{dfst y =!= a})
: acc (lift_binrel r) y
= AccIntro (fun y p -> false_elim ())
in
fun (x:top) ->
let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in
if b
then aux x (wf_r (dsnd x))
else aux' x
let lower_binrel_squashed (#a:Type u#a)
(#r:binrel u#a u#r a)
(x y:top u#a)
(p:lift_binrel_squashed r x y) | false | false | FStar.WellFounded.Util.fst | {
"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"
} | null | val lower_binrel_squashed (#a:Type u#a)
(#r:binrel u#a u#r a)
(x y:top u#a)
(p:lift_binrel_squashed r x y)
: squash (r (dsnd x) (dsnd y)) | [] | FStar.WellFounded.Util.lower_binrel_squashed | {
"file_name": "ulib/FStar.WellFounded.Util.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
x: FStar.WellFounded.Util.top ->
y: FStar.WellFounded.Util.top ->
p: FStar.WellFounded.Util.lift_binrel_squashed r x y
-> Prims.squash (r (FStar.Pervasives.dsnd x) (FStar.Pervasives.dsnd y)) | {
"end_col": 71,
"end_line": 73,
"start_col": 4,
"start_line": 72
} |
FStar.Pervasives.Lemma | val elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x) | [
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.WellFounded",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x)
= let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in
let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) ->
let p1 : (dfst y == a /\ a == a) = dfst pf in
let p2 : r (dsnd y) x = dsnd pf in
introduce dfst y == a /\ r (dsnd y) x
with eliminate dfst y == a /\ a == a
returns _
with l r. l
and FStar.Squash.return_squash p2)
in
() | val elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x)
let elim_lift_binrel (#a: Type) (r: binrel a) (y: top) (x: a)
: Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) = | false | null | true | let s:squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in
let s:squash (dfst y == a /\ r (dsnd y) x) =
FStar.Squash.bind_squash s
(fun (pf: lift_binrel r y (| a, x |)) ->
let p1:(dfst y == a /\ a == a) = dfst pf in
let p2:r (dsnd y) x = dsnd pf in
introduce dfst y == a /\ r (dsnd y) x
with eliminate dfst y == a /\ a == a
returns _
with l r . l
and FStar.Squash.return_squash p2)
in
() | {
"checked_file": "FStar.WellFounded.Util.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.WellFounded.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.WellFounded.Util.fst"
} | [
"lemma"
] | [
"FStar.WellFounded.binrel",
"FStar.WellFounded.Util.top",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.dfst",
"FStar.Pervasives.dsnd",
"FStar.Squash.bind_squash",
"FStar.WellFounded.Util.lift_binrel",
"Prims.Mkdtuple2",
"FStar.Classical.Sugar.and_intro",
"Prims.unit",
"FStar.Classical.Sugar.and_elim",
"FStar.Squash.return_squash",
"FStar.Squash.get_proof",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module FStar.WellFounded.Util
open FStar.WellFounded
#push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a)
: Lemma
(requires r y x)
(ensures lift_binrel r (| a, y |) (| a, x |))
= let t0 : top = (| a, y |) in
let t1 : top = (| a, x |) in
let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in
let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in
let pf : squash (lift_binrel r t0 t1) =
FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) ->
FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) ->
let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in
FStar.Squash.return_squash p))
in
()
let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |)) | false | false | FStar.WellFounded.Util.fst | {
"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"
} | null | val elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a)
: Lemma
(requires lift_binrel r y (| a, x |))
(ensures dfst y == a /\ r (dsnd y) x) | [] | FStar.WellFounded.Util.elim_lift_binrel | {
"file_name": "ulib/FStar.WellFounded.Util.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | r: FStar.WellFounded.binrel a -> y: FStar.WellFounded.Util.top -> x: a
-> FStar.Pervasives.Lemma (requires FStar.WellFounded.Util.lift_binrel r y (| a, x |))
(ensures FStar.Pervasives.dfst y == a /\ r (FStar.Pervasives.dsnd y) x) | {
"end_col": 6,
"end_line": 36,
"start_col": 3,
"start_line": 26
} |
Prims.Tot | val is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) : prop | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i)) | val is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) : prop
let is_permutation (#a: Type) (s0 s1: seq a) (f: index_fun s0) = | false | null | false | S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\
(forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i)) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"total"
] | [
"FStar.Sequence.Base.seq",
"FStar.Sequence.Permutation.index_fun",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Sequence.Base.length",
"Prims.l_Forall",
"FStar.Sequence.Permutation.nat_at_most",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.op_LessThan",
"FStar.Sequence.Base.index",
"Prims.prop"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"] | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) : prop | [] | FStar.Sequence.Permutation.is_permutation | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s0: FStar.Sequence.Base.seq a ->
s1: FStar.Sequence.Base.seq a ->
f: FStar.Sequence.Permutation.index_fun s0
-> Prims.prop | {
"end_col": 39,
"end_line": 31,
"start_col": 2,
"start_line": 27
} |
FStar.Pervasives.Lemma | val count_head (#a: eqtype) (x: seq a {S.length x > 0}) : Lemma (count (head x) x > 0) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a) | val count_head (#a: eqtype) (x: seq a {S.length x > 0}) : Lemma (count (head x) x > 0)
let count_head (#a: eqtype) (x: seq a {S.length x > 0}) : Lemma (count (head x) x > 0) = | false | null | true | reveal_opaque (`%count) (count #a) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Sequence.Base.length",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"FStar.Sequence.Util.count",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Sequence.Util.head",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val count_head (#a: eqtype) (x: seq a {S.length x > 0}) : Lemma (count (head x) x > 0) | [] | FStar.Sequence.Permutation.count_head | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.Sequence.Base.seq a {FStar.Sequence.Base.length x > 0}
-> FStar.Pervasives.Lemma (ensures FStar.Sequence.Util.count (FStar.Sequence.Util.head x) x > 0) | {
"end_col": 38,
"end_line": 97,
"start_col": 4,
"start_line": 97
} |
FStar.Pervasives.Lemma | val foldm_back_sym (#a:Type) (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
= elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1 | val foldm_back_sym (#a:Type) (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
let foldm_back_sym #a (m: CM.cm a) (s1: seq a) (s2: seq a)
: Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = | false | null | true | elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1 | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"FStar.Algebra.CommMonoid.cm",
"FStar.Sequence.Base.seq",
"FStar.Sequence.Permutation.foldm_back_append",
"Prims.unit",
"FStar.Sequence.Permutation.elim_monoid_laws",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Sequence.Permutation.foldm_back",
"FStar.Sequence.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x )
#push-options "--fuel 1 --ifuel 0"
let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2))
(decreases (S.length s2))
= elim_monoid_laws m;
if S.length s2 = 0
then (
assert (S.append s1 s2 `S.equal` s1);
assert (foldm_back m s2 == m.unit)
)
else (
let s2', last = un_build s2 in
calc (==)
{
foldm_back m (append s1 s2);
(==) { assert (S.equal (append s1 s2)
(S.build (append s1 s2') last)) }
foldm_back m (S.build (append s1 s2') last);
(==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) }
m.mult last (foldm_back m (append s1 s2'));
(==) { foldm_back_append m s1 s2' }
m.mult last (m.mult (foldm_back m s1) (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (m.mult last (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (foldm_back m s2);
}
)
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val foldm_back_sym (#a:Type) (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) | [] | FStar.Sequence.Permutation.foldm_back_sym | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | m: FStar.Algebra.CommMonoid.cm a -> s1: FStar.Sequence.Base.seq a -> s2: FStar.Sequence.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.append s1 s2) ==
FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.append s2 s1)) | {
"end_col": 29,
"end_line": 253,
"start_col": 4,
"start_line": 251
} |
FStar.Pervasives.Lemma | val seqperm_len (#a: _) (s0 s1: seq a) (p: seqperm s0 s1)
: Lemma (ensures S.length s0 == S.length s1) | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let seqperm_len #a (s0 s1:seq a)
(p:seqperm s0 s1)
: Lemma
(ensures S.length s0 == S.length s1)
= reveal_is_permutation s0 s1 p | val seqperm_len (#a: _) (s0 s1: seq a) (p: seqperm s0 s1)
: Lemma (ensures S.length s0 == S.length s1)
let seqperm_len #a (s0: seq a) (s1: seq a) (p: seqperm s0 s1)
: Lemma (ensures S.length s0 == S.length s1) = | false | null | true | reveal_is_permutation s0 s1 p | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"FStar.Sequence.Base.seq",
"FStar.Sequence.Permutation.seqperm",
"FStar.Sequence.Permutation.reveal_is_permutation",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"FStar.Sequence.Base.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x )
#push-options "--fuel 1 --ifuel 0"
let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2))
(decreases (S.length s2))
= elim_monoid_laws m;
if S.length s2 = 0
then (
assert (S.append s1 s2 `S.equal` s1);
assert (foldm_back m s2 == m.unit)
)
else (
let s2', last = un_build s2 in
calc (==)
{
foldm_back m (append s1 s2);
(==) { assert (S.equal (append s1 s2)
(S.build (append s1 s2') last)) }
foldm_back m (S.build (append s1 s2') last);
(==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) }
m.mult last (foldm_back m (append s1 s2'));
(==) { foldm_back_append m s1 s2' }
m.mult last (m.mult (foldm_back m s1) (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (m.mult last (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (foldm_back m s2);
}
)
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
= elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1
#push-options "--fuel 2"
let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a)
: Lemma (foldm_back m (singleton x) == x)
= elim_monoid_laws m
#pop-options
#push-options "--fuel 0"
let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) ==
m.mult x (foldm_back m (S.append s1 s2)))
= calc (==)
{
foldm_back m (S.append s1 (cons x s2));
(==) { foldm_back_append m s1 (cons x s2) }
m.mult (foldm_back m s1) (foldm_back m (cons x s2));
(==) { foldm_back_append m (singleton x) s2 }
m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2));
(==) { foldm_back_singleton m x }
m.mult (foldm_back m s1) (m.mult x (foldm_back m s2));
(==) { elim_monoid_laws m }
m.mult x (m.mult (foldm_back m s1) (foldm_back m s2));
(==) { foldm_back_append m s1 s2 }
m.mult x (foldm_back m (S.append s1 s2));
}
#pop-options
let remove_i #a (s:seq a) (i:nat{i < S.length s})
: a & seq a
= let s0, s1 = split s i in
head s1, append s0 (tail s1)
let shift_perm' #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Tot (seqperm (fst (un_build s0))
(snd (remove_i s1 (p (S.length s0 - 1)))))
= reveal_is_permutation s0 s1 p;
let s0', last = un_build s0 in
let n = S.length s0' in
let p' (i:nat{ i < n })
: j:nat{ j < n }
= if p i < p n then p i else p i - 1
in
let _, s1' = remove_i s1 (p n) in
reveal_is_permutation_nopats s0' s1' p';
p'
let shift_perm #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Pure (seqperm (fst (un_build s0))
(snd (remove_i s1 (p (S.length s0 - 1)))))
(requires True)
(ensures fun _ -> let n = S.length s0 - 1 in
S.index s1 (p n) ==
S.index s0 n)
= reveal_is_permutation s0 s1 p;
shift_perm' s0 s1 () p
let seqperm_len #a (s0 s1:seq a)
(p:seqperm s0 s1)
: Lemma | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val seqperm_len (#a: _) (s0 s1: seq a) (p: seqperm s0 s1)
: Lemma (ensures S.length s0 == S.length s1) | [] | FStar.Sequence.Permutation.seqperm_len | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s0: FStar.Sequence.Base.seq a ->
s1: FStar.Sequence.Base.seq a ->
p: FStar.Sequence.Permutation.seqperm s0 s1
-> FStar.Pervasives.Lemma (ensures FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1) | {
"end_col": 33,
"end_line": 321,
"start_col": 4,
"start_line": 321
} |
Prims.Tot | val remove_i (#a: _) (s: seq a) (i: nat{i < S.length s}) : a & seq a | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let remove_i #a (s:seq a) (i:nat{i < S.length s})
: a & seq a
= let s0, s1 = split s i in
head s1, append s0 (tail s1) | val remove_i (#a: _) (s: seq a) (i: nat{i < S.length s}) : a & seq a
let remove_i #a (s: seq a) (i: nat{i < S.length s}) : a & seq a = | false | null | false | let s0, s1 = split s i in
head s1, append s0 (tail s1) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"total"
] | [
"FStar.Sequence.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Sequence.Base.length",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Sequence.Util.head",
"FStar.Sequence.Base.append",
"FStar.Sequence.Util.tail",
"FStar.Pervasives.Native.tuple2",
"FStar.Sequence.Util.split"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x )
#push-options "--fuel 1 --ifuel 0"
let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2))
(decreases (S.length s2))
= elim_monoid_laws m;
if S.length s2 = 0
then (
assert (S.append s1 s2 `S.equal` s1);
assert (foldm_back m s2 == m.unit)
)
else (
let s2', last = un_build s2 in
calc (==)
{
foldm_back m (append s1 s2);
(==) { assert (S.equal (append s1 s2)
(S.build (append s1 s2') last)) }
foldm_back m (S.build (append s1 s2') last);
(==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) }
m.mult last (foldm_back m (append s1 s2'));
(==) { foldm_back_append m s1 s2' }
m.mult last (m.mult (foldm_back m s1) (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (m.mult last (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (foldm_back m s2);
}
)
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
= elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1
#push-options "--fuel 2"
let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a)
: Lemma (foldm_back m (singleton x) == x)
= elim_monoid_laws m
#pop-options
#push-options "--fuel 0"
let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) ==
m.mult x (foldm_back m (S.append s1 s2)))
= calc (==)
{
foldm_back m (S.append s1 (cons x s2));
(==) { foldm_back_append m s1 (cons x s2) }
m.mult (foldm_back m s1) (foldm_back m (cons x s2));
(==) { foldm_back_append m (singleton x) s2 }
m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2));
(==) { foldm_back_singleton m x }
m.mult (foldm_back m s1) (m.mult x (foldm_back m s2));
(==) { elim_monoid_laws m }
m.mult x (m.mult (foldm_back m s1) (foldm_back m s2));
(==) { foldm_back_append m s1 s2 }
m.mult x (foldm_back m (S.append s1 s2));
}
#pop-options
let remove_i #a (s:seq a) (i:nat{i < S.length s}) | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val remove_i (#a: _) (s: seq a) (i: nat{i < S.length s}) : a & seq a | [] | FStar.Sequence.Permutation.remove_i | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: FStar.Sequence.Base.seq a -> i: Prims.nat{i < FStar.Sequence.Base.length s}
-> a * FStar.Sequence.Base.seq a | {
"end_col": 32,
"end_line": 285,
"start_col": 3,
"start_line": 284
} |
FStar.Pervasives.Lemma | val reveal_is_permutation (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
(* lengths of the sequences are the same *)
S.length s0 == S.length s1 /\
(* f is injective *)
(forall x y. {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(* and f relates equal items in s0 and s1 *)
(forall (i:nat{i < S.length s0}).{:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) | val reveal_is_permutation (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
(* lengths of the sequences are the same *)
S.length s0 == S.length s1 /\
(* f is injective *)
(forall x y. {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(* and f relates equal items in s0 and s1 *)
(forall (i:nat{i < S.length s0}).{:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i)))
let reveal_is_permutation #a (s0: seq a) (s1: seq a) (f: index_fun s0) = | false | null | true | reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"FStar.Sequence.Base.seq",
"FStar.Sequence.Permutation.index_fun",
"FStar.Pervasives.reveal_opaque",
"Prims.prop",
"FStar.Sequence.Permutation.is_permutation",
"Prims.unit"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i)) | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val reveal_is_permutation (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
(* lengths of the sequences are the same *)
S.length s0 == S.length s1 /\
(* f is injective *)
(forall x y. {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(* and f relates equal items in s0 and s1 *)
(forall (i:nat{i < S.length s0}).{:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))) | [] | FStar.Sequence.Permutation.reveal_is_permutation | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s0: FStar.Sequence.Base.seq a ->
s1: FStar.Sequence.Base.seq a ->
f: FStar.Sequence.Permutation.index_fun s0
-> FStar.Pervasives.Lemma
(ensures
FStar.Sequence.Permutation.is_permutation s0 s1 f <==>
FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1 /\
(forall (x: FStar.Sequence.Permutation.nat_at_most (FStar.Sequence.Base.length s0))
(y: FStar.Sequence.Permutation.nat_at_most (FStar.Sequence.Base.length s0)).
{:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i: Prims.nat{i < FStar.Sequence.Base.length s0}).
{:pattern FStar.Sequence.Base.index s1 (f i)}
FStar.Sequence.Base.index s0 i == FStar.Sequence.Base.index s1 (f i))) | {
"end_col": 61,
"end_line": 34,
"start_col": 4,
"start_line": 34
} |
FStar.Pervasives.Lemma | val reveal_is_permutation_nopats (#a: Type) (s0 s1: seq a) (f: index_fun s0)
: Lemma
(is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\
(forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f | val reveal_is_permutation_nopats (#a: Type) (s0 s1: seq a) (f: index_fun s0)
: Lemma
(is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\
(forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i)))
let reveal_is_permutation_nopats (#a: Type) (s0 s1: seq a) (f: index_fun s0)
: Lemma
(is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\
(forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = | false | null | true | reveal_is_permutation s0 s1 f | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"FStar.Sequence.Base.seq",
"FStar.Sequence.Permutation.index_fun",
"FStar.Sequence.Permutation.reveal_is_permutation",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"FStar.Sequence.Permutation.is_permutation",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Sequence.Base.length",
"Prims.l_Forall",
"FStar.Sequence.Permutation.nat_at_most",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.op_LessThan",
"FStar.Sequence.Base.index",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val reveal_is_permutation_nopats (#a: Type) (s0 s1: seq a) (f: index_fun s0)
: Lemma
(is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\
(forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) | [] | FStar.Sequence.Permutation.reveal_is_permutation_nopats | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s0: FStar.Sequence.Base.seq a ->
s1: FStar.Sequence.Base.seq a ->
f: FStar.Sequence.Permutation.index_fun s0
-> FStar.Pervasives.Lemma
(ensures
FStar.Sequence.Permutation.is_permutation s0 s1 f <==>
FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1 /\
(forall (x: FStar.Sequence.Permutation.nat_at_most (FStar.Sequence.Base.length s0))
(y: FStar.Sequence.Permutation.nat_at_most (FStar.Sequence.Base.length s0)).
x <> y ==> f x <> f y) /\
(forall (i: Prims.nat{i < FStar.Sequence.Base.length s0}).
FStar.Sequence.Base.index s0 i == FStar.Sequence.Base.index s1 (f i))) | {
"end_col": 34,
"end_line": 45,
"start_col": 5,
"start_line": 45
} |
FStar.Pervasives.Lemma | val foldm_back_singleton (#a: _) (m: CM.cm a) (x: a) : Lemma (foldm_back m (singleton x) == x) | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a)
: Lemma (foldm_back m (singleton x) == x)
= elim_monoid_laws m | val foldm_back_singleton (#a: _) (m: CM.cm a) (x: a) : Lemma (foldm_back m (singleton x) == x)
let foldm_back_singleton (#a: _) (m: CM.cm a) (x: a) : Lemma (foldm_back m (singleton x) == x) = | false | null | true | elim_monoid_laws m | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"FStar.Algebra.CommMonoid.cm",
"FStar.Sequence.Permutation.elim_monoid_laws",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Sequence.Permutation.foldm_back",
"FStar.Sequence.Base.singleton",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x )
#push-options "--fuel 1 --ifuel 0"
let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2))
(decreases (S.length s2))
= elim_monoid_laws m;
if S.length s2 = 0
then (
assert (S.append s1 s2 `S.equal` s1);
assert (foldm_back m s2 == m.unit)
)
else (
let s2', last = un_build s2 in
calc (==)
{
foldm_back m (append s1 s2);
(==) { assert (S.equal (append s1 s2)
(S.build (append s1 s2') last)) }
foldm_back m (S.build (append s1 s2') last);
(==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) }
m.mult last (foldm_back m (append s1 s2'));
(==) { foldm_back_append m s1 s2' }
m.mult last (m.mult (foldm_back m s1) (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (m.mult last (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (foldm_back m s2);
}
)
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
= elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1
#push-options "--fuel 2"
let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a) | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 2,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val foldm_back_singleton (#a: _) (m: CM.cm a) (x: a) : Lemma (foldm_back m (singleton x) == x) | [] | FStar.Sequence.Permutation.foldm_back_singleton | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | m: FStar.Algebra.CommMonoid.cm a -> x: a
-> FStar.Pervasives.Lemma
(ensures FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.singleton x) == x) | {
"end_col": 22,
"end_line": 258,
"start_col": 4,
"start_line": 258
} |
FStar.Pervasives.Lemma | val elim_monoid_laws (#a: _) (m: CM.cm a)
: Lemma
((forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z. {:pattern (m.mult x (m.mult y z))}
m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x. {:pattern (m.mult x m.unit)} m.mult x m.unit == x)) | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x ) | val elim_monoid_laws (#a: _) (m: CM.cm a)
: Lemma
((forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z. {:pattern (m.mult x (m.mult y z))}
m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x. {:pattern (m.mult x m.unit)} m.mult x m.unit == x))
let elim_monoid_laws #a (m: CM.cm a)
: Lemma
((forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z. {:pattern (m.mult x (m.mult y z))}
m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x. {:pattern (m.mult x m.unit)} m.mult x m.unit == x)) = | false | null | true | introduce forall x y . m.mult x y == m.mult y x
with (m.commutativity x y);
introduce forall x y z . m.mult x (m.mult y z) == m.mult (m.mult x y) z
with (m.associativity x y z);
introduce forall x . m.mult x m.unit == x
with (m.identity x) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"FStar.Algebra.CommMonoid.cm",
"FStar.Classical.Sugar.forall_intro",
"Prims.eq2",
"FStar.Algebra.CommMonoid.__proj__CM__item__mult",
"FStar.Algebra.CommMonoid.__proj__CM__item__unit",
"FStar.Algebra.CommMonoid.__proj__CM__item__identity",
"Prims.squash",
"Prims.unit",
"Prims.l_Forall",
"FStar.Algebra.CommMonoid.__proj__CM__item__associativity",
"FStar.Algebra.CommMonoid.__proj__CM__item__commutativity",
"Prims.l_True",
"Prims.l_and",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_monoid_laws (#a: _) (m: CM.cm a)
: Lemma
((forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z. {:pattern (m.mult x (m.mult y z))}
m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x. {:pattern (m.mult x m.unit)} m.mult x m.unit == x)) | [] | FStar.Sequence.Permutation.elim_monoid_laws | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | m: FStar.Algebra.CommMonoid.cm a
-> FStar.Pervasives.Lemma
(ensures
(forall (x: a) (y: a). {:pattern CM?.mult m x y} CM?.mult m x y == CM?.mult m y x) /\
(forall (x: a) (y: a) (z: a). {:pattern CM?.mult m x (CM?.mult m y z)}
CM?.mult m x (CM?.mult m y z) == CM?.mult m (CM?.mult m x y) z) /\
(forall (x: a). {:pattern CM?.mult m x (CM?.unit m)} CM?.mult m x (CM?.unit m) == x)) | {
"end_col": 25,
"end_line": 215,
"start_col": 4,
"start_line": 208
} |
FStar.Pervasives.Lemma | val count_singleton_zero (#a: eqtype) (x y: a) : Lemma (x =!= y ==> count x (singleton y) == 0) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a) | val count_singleton_zero (#a: eqtype) (x y: a) : Lemma (x =!= y ==> count x (singleton y) == 0)
let count_singleton_zero (#a: eqtype) (x y: a) : Lemma (x =!= y ==> count x (singleton y) == 0) = | false | null | true | reveal_opaque (`%count) (count #a) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Pervasives.reveal_opaque",
"FStar.Sequence.Base.seq",
"Prims.nat",
"FStar.Sequence.Util.count",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.l_not",
"Prims.eq2",
"Prims.int",
"FStar.Sequence.Base.singleton",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a) | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val count_singleton_zero (#a: eqtype) (x y: a) : Lemma (x =!= y ==> count x (singleton y) == 0) | [] | FStar.Sequence.Permutation.count_singleton_zero | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a -> y: a
-> FStar.Pervasives.Lemma
(ensures ~(x == y) ==> FStar.Sequence.Util.count x (FStar.Sequence.Base.singleton y) == 0) | {
"end_col": 38,
"end_line": 87,
"start_col": 4,
"start_line": 87
} |
FStar.Pervasives.Lemma | val count_singleton_one (#a: eqtype) (x: a) : Lemma (count x (singleton x) == 1) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a) | val count_singleton_one (#a: eqtype) (x: a) : Lemma (count x (singleton x) == 1)
let count_singleton_one (#a: eqtype) (x: a) : Lemma (count x (singleton x) == 1) = | false | null | true | reveal_opaque (`%count) (count #a) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Pervasives.reveal_opaque",
"FStar.Sequence.Base.seq",
"Prims.nat",
"FStar.Sequence.Util.count",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"FStar.Sequence.Base.singleton",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a) | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val count_singleton_one (#a: eqtype) (x: a) : Lemma (count x (singleton x) == 1) | [] | FStar.Sequence.Permutation.count_singleton_one | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a
-> FStar.Pervasives.Lemma
(ensures FStar.Sequence.Util.count x (FStar.Sequence.Base.singleton x) == 1) | {
"end_col": 38,
"end_line": 84,
"start_col": 4,
"start_line": 84
} |
FStar.Pervasives.Lemma | val equal_counts_empty (#a: eqtype) (s0 s1: seq a)
: Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0) | val equal_counts_empty (#a: eqtype) (s0 s1: seq a)
: Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
let equal_counts_empty (#a: eqtype) (s0 s1: seq a)
: Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0) = | false | null | true | reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then assert (count (head s1) s1 > 0) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"Prims.op_GreaterThan",
"FStar.Sequence.Base.length",
"Prims._assert",
"Prims.b2t",
"FStar.Sequence.Util.count",
"FStar.Sequence.Util.head",
"Prims.bool",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.l_Forall",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val equal_counts_empty (#a: eqtype) (s0 s1: seq a)
: Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0) | [] | FStar.Sequence.Permutation.equal_counts_empty | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a
-> FStar.Pervasives.Lemma
(requires
FStar.Sequence.Base.length s0 == 0 /\
(forall (x: a). FStar.Sequence.Util.count x s0 == FStar.Sequence.Util.count x s1))
(ensures FStar.Sequence.Base.length s1 == 0) | {
"end_col": 35,
"end_line": 94,
"start_col": 4,
"start_line": 92
} |
FStar.Pervasives.Lemma | val foldm_back3 (#a: _) (m: CM.cm a) (s1: seq a) (x: a) (s2: seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) ==
m.mult x (foldm_back m (S.append s1 s2)))
= calc (==)
{
foldm_back m (S.append s1 (cons x s2));
(==) { foldm_back_append m s1 (cons x s2) }
m.mult (foldm_back m s1) (foldm_back m (cons x s2));
(==) { foldm_back_append m (singleton x) s2 }
m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2));
(==) { foldm_back_singleton m x }
m.mult (foldm_back m s1) (m.mult x (foldm_back m s2));
(==) { elim_monoid_laws m }
m.mult x (m.mult (foldm_back m s1) (foldm_back m s2));
(==) { foldm_back_append m s1 s2 }
m.mult x (foldm_back m (S.append s1 s2));
} | val foldm_back3 (#a: _) (m: CM.cm a) (s1: seq a) (x: a) (s2: seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2)))
let foldm_back3 #a (m: CM.cm a) (s1: seq a) (x: a) (s2: seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) = | false | null | true | calc ( == ) {
foldm_back m (S.append s1 (cons x s2));
( == ) { foldm_back_append m s1 (cons x s2) }
m.mult (foldm_back m s1) (foldm_back m (cons x s2));
( == ) { foldm_back_append m (singleton x) s2 }
m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2));
( == ) { foldm_back_singleton m x }
m.mult (foldm_back m s1) (m.mult x (foldm_back m s2));
( == ) { elim_monoid_laws m }
m.mult x (m.mult (foldm_back m s1) (foldm_back m s2));
( == ) { foldm_back_append m s1 s2 }
m.mult x (foldm_back m (S.append s1 s2));
} | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"FStar.Algebra.CommMonoid.cm",
"FStar.Sequence.Base.seq",
"FStar.Calc.calc_finish",
"Prims.eq2",
"FStar.Sequence.Permutation.foldm_back",
"FStar.Sequence.Base.append",
"FStar.Sequence.Util.cons",
"FStar.Algebra.CommMonoid.__proj__CM__item__mult",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Sequence.Base.singleton",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Sequence.Permutation.foldm_back_append",
"Prims.squash",
"FStar.Sequence.Permutation.foldm_back_singleton",
"FStar.Sequence.Permutation.elim_monoid_laws",
"Prims.l_True",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x )
#push-options "--fuel 1 --ifuel 0"
let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2))
(decreases (S.length s2))
= elim_monoid_laws m;
if S.length s2 = 0
then (
assert (S.append s1 s2 `S.equal` s1);
assert (foldm_back m s2 == m.unit)
)
else (
let s2', last = un_build s2 in
calc (==)
{
foldm_back m (append s1 s2);
(==) { assert (S.equal (append s1 s2)
(S.build (append s1 s2') last)) }
foldm_back m (S.build (append s1 s2') last);
(==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) }
m.mult last (foldm_back m (append s1 s2'));
(==) { foldm_back_append m s1 s2' }
m.mult last (m.mult (foldm_back m s1) (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (m.mult last (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (foldm_back m s2);
}
)
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
= elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1
#push-options "--fuel 2"
let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a)
: Lemma (foldm_back m (singleton x) == x)
= elim_monoid_laws m
#pop-options
#push-options "--fuel 0"
let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) == | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val foldm_back3 (#a: _) (m: CM.cm a) (s1: seq a) (x: a) (s2: seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) | [] | FStar.Sequence.Permutation.foldm_back3 | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
m: FStar.Algebra.CommMonoid.cm a ->
s1: FStar.Sequence.Base.seq a ->
x: a ->
s2: FStar.Sequence.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
FStar.Sequence.Permutation.foldm_back m
(FStar.Sequence.Base.append s1 (FStar.Sequence.Util.cons x s2)) ==
CM?.mult m x (FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.append s1 s2))) | {
"end_col": 5,
"end_line": 278,
"start_col": 4,
"start_line": 265
} |
FStar.Pervasives.Lemma | val split3_index (#a: eqtype) (s0: seq a) (x: a) (s1: seq a) (j: nat)
: Lemma (requires j < S.length (S.append s0 s1))
(ensures
(let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1))) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else () | val split3_index (#a: eqtype) (s0: seq a) (x: a) (s1: seq a) (j: nat)
: Lemma (requires j < S.length (S.append s0 s1))
(ensures
(let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1)))
let split3_index (#a: eqtype) (s0: seq a) (x: a) (s1: seq a) (j: nat)
: Lemma (requires j < S.length (S.append s0 s1))
(ensures
(let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1))) = | false | null | true | let n = S.length (S.append s0 s1) in
if j < n then () | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"lemma"
] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"Prims.nat",
"Prims.op_LessThan",
"Prims.bool",
"Prims.unit",
"FStar.Sequence.Base.length",
"FStar.Sequence.Base.append",
"Prims.b2t",
"Prims.squash",
"Prims.eq2",
"FStar.Sequence.Base.index",
"Prims.op_Addition",
"FStar.Sequence.Util.cons",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1) | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val split3_index (#a: eqtype) (s0: seq a) (x: a) (s1: seq a) (j: nat)
: Lemma (requires j < S.length (S.append s0 s1))
(ensures
(let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1))) | [] | FStar.Sequence.Permutation.split3_index | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s0: FStar.Sequence.Base.seq a -> x: a -> s1: FStar.Sequence.Base.seq a -> j: Prims.nat
-> FStar.Pervasives.Lemma
(requires j < FStar.Sequence.Base.length (FStar.Sequence.Base.append s0 s1))
(ensures
(let s = FStar.Sequence.Base.append s0 (FStar.Sequence.Util.cons x s1) in
let s' = FStar.Sequence.Base.append s0 s1 in
let n = FStar.Sequence.Base.length s0 in
(match j < n with
| true -> FStar.Sequence.Base.index s' j == FStar.Sequence.Base.index s j
| _ -> FStar.Sequence.Base.index s' j == FStar.Sequence.Base.index s (j + 1))
<:
Type0)) | {
"end_col": 11,
"end_line": 61,
"start_col": 3,
"start_line": 59
} |
Prims.Pure | val shift_perm:
#a: _ ->
s0: seq a ->
s1: seq a ->
squash (S.length s0 == S.length s1 /\ S.length s0 > 0) ->
p: seqperm s0 s1
-> Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1)))))
(requires True)
(ensures
fun _ ->
let n = S.length s0 - 1 in
S.index s1 (p n) == S.index s0 n) | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_perm #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Pure (seqperm (fst (un_build s0))
(snd (remove_i s1 (p (S.length s0 - 1)))))
(requires True)
(ensures fun _ -> let n = S.length s0 - 1 in
S.index s1 (p n) ==
S.index s0 n)
= reveal_is_permutation s0 s1 p;
shift_perm' s0 s1 () p | val shift_perm:
#a: _ ->
s0: seq a ->
s1: seq a ->
squash (S.length s0 == S.length s1 /\ S.length s0 > 0) ->
p: seqperm s0 s1
-> Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1)))))
(requires True)
(ensures
fun _ ->
let n = S.length s0 - 1 in
S.index s1 (p n) == S.index s0 n)
let shift_perm
#a
(s0: seq a)
(s1: seq a)
(_: squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p: seqperm s0 s1)
: Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1)))))
(requires True)
(ensures
fun _ ->
let n = S.length s0 - 1 in
S.index s1 (p n) == S.index s0 n) = | false | null | false | reveal_is_permutation s0 s1 p;
shift_perm' s0 s1 () p | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [] | [
"FStar.Sequence.Base.seq",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Sequence.Base.length",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Sequence.Permutation.seqperm",
"FStar.Sequence.Permutation.shift_perm'",
"Prims.unit",
"FStar.Sequence.Permutation.reveal_is_permutation",
"FStar.Pervasives.Native.fst",
"FStar.Sequence.Util.un_build",
"FStar.Pervasives.Native.snd",
"FStar.Sequence.Permutation.remove_i",
"Prims.op_Subtraction",
"Prims.l_True",
"FStar.Sequence.Base.index",
"Prims.int"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x )
#push-options "--fuel 1 --ifuel 0"
let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2))
(decreases (S.length s2))
= elim_monoid_laws m;
if S.length s2 = 0
then (
assert (S.append s1 s2 `S.equal` s1);
assert (foldm_back m s2 == m.unit)
)
else (
let s2', last = un_build s2 in
calc (==)
{
foldm_back m (append s1 s2);
(==) { assert (S.equal (append s1 s2)
(S.build (append s1 s2') last)) }
foldm_back m (S.build (append s1 s2') last);
(==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) }
m.mult last (foldm_back m (append s1 s2'));
(==) { foldm_back_append m s1 s2' }
m.mult last (m.mult (foldm_back m s1) (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (m.mult last (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (foldm_back m s2);
}
)
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
= elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1
#push-options "--fuel 2"
let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a)
: Lemma (foldm_back m (singleton x) == x)
= elim_monoid_laws m
#pop-options
#push-options "--fuel 0"
let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) ==
m.mult x (foldm_back m (S.append s1 s2)))
= calc (==)
{
foldm_back m (S.append s1 (cons x s2));
(==) { foldm_back_append m s1 (cons x s2) }
m.mult (foldm_back m s1) (foldm_back m (cons x s2));
(==) { foldm_back_append m (singleton x) s2 }
m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2));
(==) { foldm_back_singleton m x }
m.mult (foldm_back m s1) (m.mult x (foldm_back m s2));
(==) { elim_monoid_laws m }
m.mult x (m.mult (foldm_back m s1) (foldm_back m s2));
(==) { foldm_back_append m s1 s2 }
m.mult x (foldm_back m (S.append s1 s2));
}
#pop-options
let remove_i #a (s:seq a) (i:nat{i < S.length s})
: a & seq a
= let s0, s1 = split s i in
head s1, append s0 (tail s1)
let shift_perm' #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Tot (seqperm (fst (un_build s0))
(snd (remove_i s1 (p (S.length s0 - 1)))))
= reveal_is_permutation s0 s1 p;
let s0', last = un_build s0 in
let n = S.length s0' in
let p' (i:nat{ i < n })
: j:nat{ j < n }
= if p i < p n then p i else p i - 1
in
let _, s1' = remove_i s1 (p n) in
reveal_is_permutation_nopats s0' s1' p';
p'
let shift_perm #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Pure (seqperm (fst (un_build s0))
(snd (remove_i s1 (p (S.length s0 - 1)))))
(requires True)
(ensures fun _ -> let n = S.length s0 - 1 in
S.index s1 (p n) == | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_perm:
#a: _ ->
s0: seq a ->
s1: seq a ->
squash (S.length s0 == S.length s1 /\ S.length s0 > 0) ->
p: seqperm s0 s1
-> Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1)))))
(requires True)
(ensures
fun _ ->
let n = S.length s0 - 1 in
S.index s1 (p n) == S.index s0 n) | [] | FStar.Sequence.Permutation.shift_perm | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s0: FStar.Sequence.Base.seq a ->
s1: FStar.Sequence.Base.seq a ->
_:
Prims.squash (FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1 /\
FStar.Sequence.Base.length s0 > 0) ->
p: FStar.Sequence.Permutation.seqperm s0 s1
-> Prims.Pure
(FStar.Sequence.Permutation.seqperm (FStar.Pervasives.Native.fst (FStar.Sequence.Util.un_build s0
))
(FStar.Pervasives.Native.snd (FStar.Sequence.Permutation.remove_i s1
(p (FStar.Sequence.Base.length s0 - 1))))) | {
"end_col": 26,
"end_line": 315,
"start_col": 4,
"start_line": 314
} |
Prims.Tot | val find (#a: eqtype) (x: a) (s: seq a {count x s > 0})
: Tot
(frags:
(seq a & seq a)
{ let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` (S.append (fst frags) (cons x (snd frags))) }) (decreases (S.length s)) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
) | val find (#a: eqtype) (x: a) (s: seq a {count x s > 0})
: Tot
(frags:
(seq a & seq a)
{ let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` (S.append (fst frags) (cons x (snd frags))) }) (decreases (S.length s))
let rec find (#a: eqtype) (x: a) (s: seq a {count x s > 0})
: Tot
(frags:
(seq a & seq a)
{ let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` (S.append (fst frags) (cons x (snd frags))) }) (decreases (S.length s)) = | false | null | false | reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else
(let pfx, sfx = find x (tail s) in
assert (S.equal (tail s) (S.append pfx (cons x sfx)));
assert (S.equal s (cons (head s) (tail s)));
cons (head s) pfx, sfx) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"total",
""
] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Sequence.Util.count",
"Prims.op_Equality",
"FStar.Sequence.Util.head",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Sequence.Base.empty",
"FStar.Sequence.Util.tail",
"Prims.bool",
"FStar.Sequence.Util.cons",
"Prims.unit",
"Prims._assert",
"FStar.Sequence.Base.equal",
"FStar.Sequence.Base.append",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Prims.nat",
"FStar.Sequence.Base.length",
"FStar.Sequence.Permutation.find",
"FStar.Pervasives.reveal_opaque"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags)) | false | false | FStar.Sequence.Permutation.fst | {
"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"
} | null | val find (#a: eqtype) (x: a) (s: seq a {count x s > 0})
: Tot
(frags:
(seq a & seq a)
{ let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` (S.append (fst frags) (cons x (snd frags))) }) (decreases (S.length s)) | [
"recursion"
] | FStar.Sequence.Permutation.find | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: a -> s: FStar.Sequence.Base.seq a {FStar.Sequence.Util.count x s > 0}
-> Prims.Tot
(frags:
(FStar.Sequence.Base.seq a * FStar.Sequence.Base.seq a)
{ let s' =
FStar.Sequence.Base.append (FStar.Pervasives.Native.fst frags)
(FStar.Pervasives.Native.snd frags)
in
let n = FStar.Sequence.Base.length (FStar.Pervasives.Native.fst frags) in
FStar.Sequence.Base.equal s
(FStar.Sequence.Base.append (FStar.Pervasives.Native.fst frags)
(FStar.Sequence.Util.cons x (FStar.Pervasives.Native.snd frags))) }) | {
"end_col": 5,
"end_line": 80,
"start_col": 4,
"start_line": 70
} |
Prims.Tot | val shift_perm':
#a: _ ->
s0: seq a ->
s1: seq a ->
squash (S.length s0 == S.length s1 /\ S.length s0 > 0) ->
p: seqperm s0 s1
-> Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_perm' #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Tot (seqperm (fst (un_build s0))
(snd (remove_i s1 (p (S.length s0 - 1)))))
= reveal_is_permutation s0 s1 p;
let s0', last = un_build s0 in
let n = S.length s0' in
let p' (i:nat{ i < n })
: j:nat{ j < n }
= if p i < p n then p i else p i - 1
in
let _, s1' = remove_i s1 (p n) in
reveal_is_permutation_nopats s0' s1' p';
p' | val shift_perm':
#a: _ ->
s0: seq a ->
s1: seq a ->
squash (S.length s0 == S.length s1 /\ S.length s0 > 0) ->
p: seqperm s0 s1
-> Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1)))))
let shift_perm'
#a
(s0: seq a)
(s1: seq a)
(_: squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p: seqperm s0 s1)
: Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) = | false | null | false | reveal_is_permutation s0 s1 p;
let s0', last = un_build s0 in
let n = S.length s0' in
let p' (i: nat{i < n}) : j: nat{j < n} = if p i < p n then p i else p i - 1 in
let _, s1' = remove_i s1 (p n) in
reveal_is_permutation_nopats s0' s1' p';
p' | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"total"
] | [
"FStar.Sequence.Base.seq",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Sequence.Base.length",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Sequence.Permutation.seqperm",
"Prims.unit",
"FStar.Sequence.Permutation.reveal_is_permutation_nopats",
"FStar.Pervasives.Native.fst",
"FStar.Sequence.Util.un_build",
"FStar.Pervasives.Native.snd",
"FStar.Sequence.Permutation.remove_i",
"Prims.op_Subtraction",
"FStar.Pervasives.Native.tuple2",
"Prims.op_LessThan",
"Prims.bool",
"FStar.Sequence.Permutation.reveal_is_permutation"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x )
#push-options "--fuel 1 --ifuel 0"
let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2))
(decreases (S.length s2))
= elim_monoid_laws m;
if S.length s2 = 0
then (
assert (S.append s1 s2 `S.equal` s1);
assert (foldm_back m s2 == m.unit)
)
else (
let s2', last = un_build s2 in
calc (==)
{
foldm_back m (append s1 s2);
(==) { assert (S.equal (append s1 s2)
(S.build (append s1 s2') last)) }
foldm_back m (S.build (append s1 s2') last);
(==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) }
m.mult last (foldm_back m (append s1 s2'));
(==) { foldm_back_append m s1 s2' }
m.mult last (m.mult (foldm_back m s1) (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (m.mult last (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (foldm_back m s2);
}
)
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
= elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1
#push-options "--fuel 2"
let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a)
: Lemma (foldm_back m (singleton x) == x)
= elim_monoid_laws m
#pop-options
#push-options "--fuel 0"
let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) ==
m.mult x (foldm_back m (S.append s1 s2)))
= calc (==)
{
foldm_back m (S.append s1 (cons x s2));
(==) { foldm_back_append m s1 (cons x s2) }
m.mult (foldm_back m s1) (foldm_back m (cons x s2));
(==) { foldm_back_append m (singleton x) s2 }
m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2));
(==) { foldm_back_singleton m x }
m.mult (foldm_back m s1) (m.mult x (foldm_back m s2));
(==) { elim_monoid_laws m }
m.mult x (m.mult (foldm_back m s1) (foldm_back m s2));
(==) { foldm_back_append m s1 s2 }
m.mult x (foldm_back m (S.append s1 s2));
}
#pop-options
let remove_i #a (s:seq a) (i:nat{i < S.length s})
: a & seq a
= let s0, s1 = split s i in
head s1, append s0 (tail s1)
let shift_perm' #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Tot (seqperm (fst (un_build s0)) | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_perm':
#a: _ ->
s0: seq a ->
s1: seq a ->
squash (S.length s0 == S.length s1 /\ S.length s0 > 0) ->
p: seqperm s0 s1
-> Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) | [] | FStar.Sequence.Permutation.shift_perm' | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s0: FStar.Sequence.Base.seq a ->
s1: FStar.Sequence.Base.seq a ->
_:
Prims.squash (FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1 /\
FStar.Sequence.Base.length s0 > 0) ->
p: FStar.Sequence.Permutation.seqperm s0 s1
-> FStar.Sequence.Permutation.seqperm (FStar.Pervasives.Native.fst (FStar.Sequence.Util.un_build s0
))
(FStar.Pervasives.Native.snd (FStar.Sequence.Permutation.remove_i s1
(p (FStar.Sequence.Base.length s0 - 1)))) | {
"end_col": 6,
"end_line": 302,
"start_col": 4,
"start_line": 293
} |
FStar.Pervasives.Lemma | val foldm_back_perm (#a:_)
(m:CM.cm a)
(s0:seq a)
(s1:seq a)
(p:seqperm s0 s1)
: Lemma
(ensures foldm_back m s0 == foldm_back m s1) | [
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Algebra.CommMonoid",
"short_module": "CM"
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec foldm_back_perm #a m s0 s1 p
: Lemma
(ensures foldm_back m s0 == foldm_back m s1)
(decreases (S.length s0))
= seqperm_len s0 s1 p;
if S.length s0 = 0 then (
assert (S.equal s0 s1)
)
else (
let n0 = S.length s0 - 1 in
let prefix, last = un_build s0 in
let prefix', suffix' = split s1 (p n0) in
let last', suffix' = suffix' $@ 0, drop suffix' 1 in
let s1' = snd (remove_i s1 (p n0)) in
let p' : seqperm prefix s1' = shift_perm s0 s1 () p in
assert (last == last');
calc
(==)
{
foldm_back m s1;
(==) { assert (s1 `S.equal` S.append prefix' (cons last' suffix')) }
foldm_back m (S.append prefix' (cons last' suffix'));
(==) { foldm_back3 m prefix' last' suffix' }
m.mult last' (foldm_back m (append prefix' suffix'));
(==) { assert (S.equal (append prefix' suffix') s1') }
m.mult last' (foldm_back m s1');
(==) { foldm_back_perm m prefix s1' p' }
m.mult last' (foldm_back m prefix);
(==) { }
foldm_back m s0;
}
) | val foldm_back_perm (#a:_)
(m:CM.cm a)
(s0:seq a)
(s1:seq a)
(p:seqperm s0 s1)
: Lemma
(ensures foldm_back m s0 == foldm_back m s1)
let rec foldm_back_perm #a m s0 s1 p
: Lemma (ensures foldm_back m s0 == foldm_back m s1) (decreases (S.length s0)) = | false | null | true | seqperm_len s0 s1 p;
if S.length s0 = 0
then (assert (S.equal s0 s1))
else
(let n0 = S.length s0 - 1 in
let prefix, last = un_build s0 in
let prefix', suffix' = split s1 (p n0) in
let last', suffix' = suffix' $@ 0, drop suffix' 1 in
let s1' = snd (remove_i s1 (p n0)) in
let p':seqperm prefix s1' = shift_perm s0 s1 () p in
assert (last == last');
calc ( == ) {
foldm_back m s1;
( == ) { assert (s1 `S.equal` (S.append prefix' (cons last' suffix'))) }
foldm_back m (S.append prefix' (cons last' suffix'));
( == ) { foldm_back3 m prefix' last' suffix' }
m.mult last' (foldm_back m (append prefix' suffix'));
( == ) { assert (S.equal (append prefix' suffix') s1') }
m.mult last' (foldm_back m s1');
( == ) { foldm_back_perm m prefix s1' p' }
m.mult last' (foldm_back m prefix);
( == ) { () }
foldm_back m s0;
}) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"",
"lemma"
] | [
"FStar.Algebra.CommMonoid.cm",
"FStar.Sequence.Base.seq",
"FStar.Sequence.Permutation.seqperm",
"Prims.op_Equality",
"Prims.int",
"FStar.Sequence.Base.length",
"Prims._assert",
"FStar.Sequence.Base.equal",
"Prims.bool",
"FStar.Calc.calc_finish",
"Prims.eq2",
"FStar.Sequence.Permutation.foldm_back",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Algebra.CommMonoid.__proj__CM__item__mult",
"FStar.Sequence.Base.append",
"FStar.Sequence.Util.cons",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Sequence.Permutation.foldm_back3",
"FStar.Sequence.Permutation.foldm_back_perm",
"FStar.Sequence.Permutation.shift_perm",
"FStar.Pervasives.Native.snd",
"FStar.Sequence.Permutation.remove_i",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Sequence.Base.op_Dollar_At",
"FStar.Sequence.Base.drop",
"FStar.Sequence.Util.split",
"FStar.Sequence.Util.un_build",
"Prims.op_Subtraction",
"FStar.Sequence.Permutation.seqperm_len",
"Prims.l_True",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f)
module CM = FStar.Algebra.CommMonoid
let elim_monoid_laws #a (m:CM.cm a)
: Lemma (
(forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\
(forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\
(forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x)
)
= introduce forall x y. m.mult x y == m.mult y x
with ( m.commutativity x y );
introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z
with ( m.associativity x y z );
introduce forall x. m.mult x m.unit == x
with ( m.identity x )
#push-options "--fuel 1 --ifuel 0"
let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2))
(decreases (S.length s2))
= elim_monoid_laws m;
if S.length s2 = 0
then (
assert (S.append s1 s2 `S.equal` s1);
assert (foldm_back m s2 == m.unit)
)
else (
let s2', last = un_build s2 in
calc (==)
{
foldm_back m (append s1 s2);
(==) { assert (S.equal (append s1 s2)
(S.build (append s1 s2') last)) }
foldm_back m (S.build (append s1 s2') last);
(==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) }
m.mult last (foldm_back m (append s1 s2'));
(==) { foldm_back_append m s1 s2' }
m.mult last (m.mult (foldm_back m s1) (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (m.mult last (foldm_back m s2'));
(==) { }
m.mult (foldm_back m s1) (foldm_back m s2);
}
)
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a)
: Lemma
(ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
= elim_monoid_laws m;
foldm_back_append m s1 s2;
foldm_back_append m s2 s1
#push-options "--fuel 2"
let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a)
: Lemma (foldm_back m (singleton x) == x)
= elim_monoid_laws m
#pop-options
#push-options "--fuel 0"
let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a)
: Lemma (foldm_back m (S.append s1 (cons x s2)) ==
m.mult x (foldm_back m (S.append s1 s2)))
= calc (==)
{
foldm_back m (S.append s1 (cons x s2));
(==) { foldm_back_append m s1 (cons x s2) }
m.mult (foldm_back m s1) (foldm_back m (cons x s2));
(==) { foldm_back_append m (singleton x) s2 }
m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2));
(==) { foldm_back_singleton m x }
m.mult (foldm_back m s1) (m.mult x (foldm_back m s2));
(==) { elim_monoid_laws m }
m.mult x (m.mult (foldm_back m s1) (foldm_back m s2));
(==) { foldm_back_append m s1 s2 }
m.mult x (foldm_back m (S.append s1 s2));
}
#pop-options
let remove_i #a (s:seq a) (i:nat{i < S.length s})
: a & seq a
= let s0, s1 = split s i in
head s1, append s0 (tail s1)
let shift_perm' #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Tot (seqperm (fst (un_build s0))
(snd (remove_i s1 (p (S.length s0 - 1)))))
= reveal_is_permutation s0 s1 p;
let s0', last = un_build s0 in
let n = S.length s0' in
let p' (i:nat{ i < n })
: j:nat{ j < n }
= if p i < p n then p i else p i - 1
in
let _, s1' = remove_i s1 (p n) in
reveal_is_permutation_nopats s0' s1' p';
p'
let shift_perm #a
(s0 s1:seq a)
(_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0))
(p:seqperm s0 s1)
: Pure (seqperm (fst (un_build s0))
(snd (remove_i s1 (p (S.length s0 - 1)))))
(requires True)
(ensures fun _ -> let n = S.length s0 - 1 in
S.index s1 (p n) ==
S.index s0 n)
= reveal_is_permutation s0 s1 p;
shift_perm' s0 s1 () p
let seqperm_len #a (s0 s1:seq a)
(p:seqperm s0 s1)
: Lemma
(ensures S.length s0 == S.length s1)
= reveal_is_permutation s0 s1 p
let rec foldm_back_perm #a m s0 s1 p
: Lemma
(ensures foldm_back m s0 == foldm_back m s1) | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val foldm_back_perm (#a:_)
(m:CM.cm a)
(s0:seq a)
(s1:seq a)
(p:seqperm s0 s1)
: Lemma
(ensures foldm_back m s0 == foldm_back m s1) | [
"recursion"
] | FStar.Sequence.Permutation.foldm_back_perm | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
m: FStar.Algebra.CommMonoid.cm a ->
s0: FStar.Sequence.Base.seq a ->
s1: FStar.Sequence.Base.seq a ->
p: FStar.Sequence.Permutation.seqperm s0 s1
-> FStar.Pervasives.Lemma
(ensures
FStar.Sequence.Permutation.foldm_back m s0 == FStar.Sequence.Permutation.foldm_back m s1)
(decreases FStar.Sequence.Base.length s0) | {
"end_col": 5,
"end_line": 354,
"start_col": 4,
"start_line": 327
} |
Prims.Tot | val permutation_from_equal_counts
(#a:eqtype)
(s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1) | [
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Sequence",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Sequence.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
(decreases (S.length s0))
= if S.length s0 = 0
then (
count_empty s0;
assert (forall x. count x s0 = 0);
let f : index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f
)
else (
count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x. count x (tail s0) == count x (S.append pfx sfx)
with
(
if x = head s0
then (
calc (eq2 #int) {
count x (tail s0) <: int;
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x
}
count x s0 - 1 <: int;
(==) {}
count x s1 - 1 <: int;
(==) {}
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
(==) { count_singleton_one x }
count x pfx + count x sfx <: int;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
}
)
else (
calc (==) {
count x (tail s0);
(==) {
assert (s0 `S.equal` cons (head s0) (tail s0));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)
}
count x s0;
(==) { }
count x s1;
(==) { }
count x (S.append pfx (cons (head s0) sfx));
(==) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
(==) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) ;
(==) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
(==) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}
)
);
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f : index_fun s0 =
fun i -> if i = 0
then n
else if f' (i - 1) < n
then f' (i - 1)
else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y. x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (
if f x = n || f y = n
then ()
else if f' (x - 1) < n
then (
assert (f x == f' (x - 1));
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
else (
assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n
then assert (f y == f' (y - 1))
else assert (f y == f' (y - 1) + 1)
)
)
);
reveal_is_permutation_nopats s0 s1 f; f) | val permutation_from_equal_counts
(#a:eqtype)
(s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1)
let rec permutation_from_equal_counts
(#a: eqtype)
(s0: seq a)
(s1: seq a {(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1) (decreases (S.length s0)) = | false | null | false | if S.length s0 = 0
then
(count_empty s0;
assert (forall x. count x s0 = 0);
let f:index_fun s0 = fun i -> i in
reveal_is_permutation_nopats s0 s1 f;
equal_counts_empty s0 s1;
f)
else
(count_head s0;
let pfx, sfx = find (head s0) s1 in
introduce forall x . count x (tail s0) == count x (S.append pfx sfx)
with (if x = head s0
then
(calc (eq2 #int) {
count x (tail s0) <: int;
( == ) { (assert (s0 `S.equal` (cons (head s0) (tail s0)));
lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0);
count_singleton_one x) }
count x s0 - 1 <: int;
( == ) { () }
count x s1 - 1 <: int;
( == ) { () }
count x (S.append pfx (cons (head s0) sfx)) - 1 <: int;
( == ) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx) - 1 <: int;
( == ) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int;
( == ) { count_singleton_one x }
count x pfx + count x sfx <: int;
( == ) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx) <: int;
})
else
(calc ( == ) {
count x (tail s0);
( == ) { (assert (s0 `S.equal` (cons (head s0) (tail s0)));
lemma_append_count_aux x (S.singleton (head s0)) (tail s0);
count_singleton_zero x (head s0)) }
count x s0;
( == ) { () }
count x s1;
( == ) { () }
count x (S.append pfx (cons (head s0) sfx));
( == ) { lemma_append_count_aux x pfx (cons (head s0) sfx) }
count x pfx + count x (cons (head s0) sfx);
( == ) { lemma_append_count_aux x (S.singleton (head s0)) sfx }
count x pfx + (count x (S.singleton (head s0)) + count x sfx);
( == ) { count_singleton_zero x (head s0) }
count x pfx + count x sfx;
( == ) { lemma_append_count_aux x pfx sfx }
count x (S.append pfx sfx);
}));
let s1' = (S.append pfx sfx) in
let f' = permutation_from_equal_counts (tail s0) s1' in
reveal_is_permutation_nopats (tail s0) s1' f';
let n = S.length pfx in
let f:index_fun s0 =
fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1
in
assert (S.length s0 == S.length s1);
assert (forall x y. x <> y ==> f' x <> f' y);
introduce forall x y . x <> y ==> f x <> f y
with (introduce _ ==> _
with _. (if f x = n || f y = n
then ()
else
if f' (x - 1) < n
then
(assert (f x == f' (x - 1));
if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1))
else
(assert (f x == f' (x - 1) + 1);
if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1))
));
reveal_is_permutation_nopats s0 s1 f;
f) | {
"checked_file": "FStar.Sequence.Permutation.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Util.fst.checked",
"FStar.Sequence.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Calc.fsti.checked",
"FStar.Algebra.CommMonoid.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Sequence.Permutation.fst"
} | [
"",
"total"
] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"Prims.l_Forall",
"Prims.eq2",
"Prims.nat",
"FStar.Sequence.Util.count",
"Prims.op_Equality",
"Prims.int",
"FStar.Sequence.Base.length",
"Prims.unit",
"FStar.Sequence.Permutation.equal_counts_empty",
"FStar.Sequence.Permutation.reveal_is_permutation_nopats",
"FStar.Sequence.Permutation.index_fun",
"FStar.Sequence.Permutation.nat_at_most",
"Prims._assert",
"Prims.b2t",
"FStar.Sequence.Util.count_empty",
"Prims.bool",
"FStar.Classical.Sugar.forall_intro",
"Prims.l_imp",
"Prims.op_disEquality",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"Prims.op_BarBar",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.l_or",
"FStar.Sequence.Util.tail",
"Prims.op_Addition",
"FStar.Sequence.Permutation.seqperm",
"FStar.Sequence.Permutation.permutation_from_equal_counts",
"FStar.Sequence.Base.append",
"FStar.Sequence.Util.head",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Sequence.Base.singleton",
"FStar.Sequence.Util.cons",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Sequence.Permutation.count_singleton_one",
"FStar.Sequence.Util.lemma_append_count_aux",
"FStar.Sequence.Base.equal",
"FStar.Sequence.Permutation.count_singleton_zero",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"FStar.Sequence.Permutation.find",
"FStar.Sequence.Permutation.count_head"
] | [] | (*
Copyright 2021 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.
Author: N. Swamy
*)
module FStar.Sequence.Permutation
open FStar.Sequence
open FStar.Calc
open FStar.Sequence.Util
module S = FStar.Sequence
////////////////////////////////////////////////////////////////////////////////
[@@"opaque_to_smt"]
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) =
S.length s0 == S.length s1 /\
(forall x y. // {:pattern f x; f y}
x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))}
S.index s0 i == S.index s1 (f i))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0)
= reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0)
: Lemma (is_permutation s0 s1 f <==>
S.length s0 == S.length s1 /\
(forall x y. x <> y ==> f x <> f y) /\
(forall (i:nat{i < S.length s0}).
S.index s0 i == S.index s1 (f i)))
= reveal_is_permutation s0 s1 f
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat)
: Lemma
(requires j < S.length (S.append s0 s1))
(ensures (
let s = S.append s0 (cons x s1) in
let s' = S.append s0 s1 in
let n = S.length s0 in
if j < n then S.index s' j == S.index s j
else S.index s' j == S.index s (j + 1)
))
= let n = S.length (S.append s0 s1) in
if j < n then ()
else ()
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 })
: Tot (frags:(seq a & seq a) {
let s' = S.append (fst frags) (snd frags) in
let n = S.length (fst frags) in
s `S.equal` S.append (fst frags) (cons x (snd frags))
}) (decreases (S.length s))
= reveal_opaque (`%count) (count #a);
if head s = x
then S.empty, tail s
else (
let pfx, sfx = find x (tail s) in
assert (S.equal (tail s)
(S.append pfx (cons x sfx)));
assert (S.equal s
(cons (head s) (tail s)));
cons (head s) pfx, sfx
)
let count_singleton_one (#a:eqtype) (x:a)
: Lemma (count x (singleton x) == 1)
= reveal_opaque (`%count) (count #a)
let count_singleton_zero (#a:eqtype) (x y:a)
: Lemma (x =!= y ==> count x (singleton y) == 0)
= reveal_opaque (`%count) (count #a)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a)
: Lemma
(requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1))
(ensures S.length s1 == 0)
= reveal_opaque (`%count) (count #a);
if S.length s1 > 0 then
assert (count (head s1) s1 > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 })
: Lemma (count (head x) x > 0)
= reveal_opaque (`%count) (count #a)
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1) | false | false | FStar.Sequence.Permutation.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val permutation_from_equal_counts
(#a:eqtype)
(s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)})
: Tot (seqperm s0 s1) | [
"recursion"
] | FStar.Sequence.Permutation.permutation_from_equal_counts | {
"file_name": "ulib/experimental/FStar.Sequence.Permutation.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
s0: FStar.Sequence.Base.seq a ->
s1:
FStar.Sequence.Base.seq a
{forall (x: a). FStar.Sequence.Util.count x s0 == FStar.Sequence.Util.count x s1}
-> Prims.Tot (FStar.Sequence.Permutation.seqperm s0 s1) | {
"end_col": 46,
"end_line": 199,
"start_col": 4,
"start_line": 103
} |
Prims.Tot | val pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> nat_mod m | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let pow_mod #m a b = pow_mod_ #m a b | val pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> nat_mod m
let pow_mod #m a b = | false | null | false | pow_mod_ #m a b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"total"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Prims.nat",
"Lib.NatMod.pow_mod_"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = () | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> nat_mod m | [] | Lib.NatMod.pow_mod | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Prims.nat -> Lib.NatMod.nat_mod m | {
"end_col": 36,
"end_line": 122,
"start_col": 21,
"start_line": 122
} |
FStar.Pervasives.Lemma | val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b) | val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
let lemma_pow_double a b = | false | null | true | let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.nat",
"Lib.NatMod.lemma_pow_nat_is_pow",
"Prims.op_Addition",
"Prims.unit",
"FStar.Mul.op_Star",
"Lib.Exponentiation.Definition.lemma_pow_double",
"Lib.Exponentiation.Definition.comm_monoid",
"Lib.NatMod.mk_nat_comm_monoid"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b)) | [] | Lib.NatMod.lemma_pow_double | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.int -> b: Prims.nat
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow (a * a) b == Lib.NatMod.pow a (b + b)) | {
"end_col": 32,
"end_line": 71,
"start_col": 26,
"start_line": 67
} |
FStar.Pervasives.Lemma | val lemma_mod_distributivity_add_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (add_mod a b) c == add_mod (mul_mod a c) (mul_mod b c)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b | val lemma_mod_distributivity_add_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (add_mod a b) c == add_mod (mul_mod a c) (mul_mod b c))
let lemma_mod_distributivity_add_left #m a b c = | false | null | true | lemma_mod_distributivity_add_right c a b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"Lib.NatMod.lemma_mod_distributivity_add_right",
"Prims.unit"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
} | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mod_distributivity_add_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (add_mod a b) c == add_mod (mul_mod a c) (mul_mod b c)) | [] | Lib.NatMod.lemma_mod_distributivity_add_left | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.mul_mod (Lib.NatMod.add_mod a b) c ==
Lib.NatMod.add_mod (Lib.NatMod.mul_mod a c) (Lib.NatMod.mul_mod b c)) | {
"end_col": 42,
"end_line": 244,
"start_col": 2,
"start_line": 244
} |
FStar.Pervasives.Lemma | val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n | val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
let lemma_pow_mul_base a b n = | false | null | true | let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.nat",
"Lib.NatMod.lemma_pow_nat_is_pow",
"FStar.Mul.op_Star",
"Prims.unit",
"Lib.Exponentiation.Definition.lemma_pow_mul_base",
"Lib.Exponentiation.Definition.comm_monoid",
"Lib.NatMod.mk_nat_comm_monoid"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n) | [] | Lib.NatMod.lemma_pow_mul_base | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.int -> b: Prims.int -> n: Prims.nat
-> FStar.Pervasives.Lemma
(ensures Lib.NatMod.pow a n * Lib.NatMod.pow b n == Lib.NatMod.pow (a * b) n) | {
"end_col": 32,
"end_line": 79,
"start_col": 30,
"start_line": 74
} |
FStar.Pervasives.Lemma | val lemma_pow_mod_prime_zero: #m:prime -> a:nat_mod m -> b:pos ->
Lemma (pow_mod #m a b = 0 <==> a = 0) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_pow_mod_prime_zero #m a b =
lemma_pow_mod #m a b;
Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b;
Classical.move_requires lemma_pow_zero b | val lemma_pow_mod_prime_zero: #m:prime -> a:nat_mod m -> b:pos ->
Lemma (pow_mod #m a b = 0 <==> a = 0)
let lemma_pow_mod_prime_zero #m a b = | false | null | true | lemma_pow_mod #m a b;
Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b;
Classical.move_requires lemma_pow_zero b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Lib.NatMod.nat_mod",
"Prims.pos",
"FStar.Classical.move_requires",
"Prims.l_True",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Lib.NatMod.pow",
"Lib.NatMod.lemma_pow_zero",
"Prims.unit",
"FStar.Classical.move_requires_2",
"Prims.op_Modulus",
"Lib.NatMod.lemma_pow_mod_prime_zero_",
"Lib.NatMod.lemma_pow_mod"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else ()
let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0)
let lemma_mul_mod_zero2 n x y =
if x % n = 0 then
Math.Lemmas.lemma_mod_mul_distr_l x y n
else
Math.Lemmas.lemma_mod_mul_distr_r x y n
let lemma_mul_mod_prime_zero #m a b =
Classical.move_requires_3 Euclid.euclid_prime m a b;
Classical.move_requires_3 lemma_mul_mod_zero2 m a b
val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma
(requires pow a b % m = 0)
(ensures a = 0)
let rec lemma_pow_mod_prime_zero_ #m a b =
if b = 1 then lemma_pow1 a
else begin
let r1 = pow a (b - 1) % m in
lemma_pow_unfold a b;
assert (a * pow a (b - 1) % m = 0);
Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m;
lemma_mul_mod_prime_zero #m a r1;
//assert (a = 0 \/ r1 = 0);
if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_mod_prime_zero: #m:prime -> a:nat_mod m -> b:pos ->
Lemma (pow_mod #m a b = 0 <==> a = 0) | [] | Lib.NatMod.lemma_pow_mod_prime_zero | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Prims.pos
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow_mod a b = 0 <==> a = 0) | {
"end_col": 42,
"end_line": 437,
"start_col": 2,
"start_line": 435
} |
FStar.Pervasives.Lemma | val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m) | val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
let lemma_pow_mul x n m = | false | null | true | let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.nat",
"Lib.NatMod.lemma_pow_nat_is_pow",
"FStar.Mul.op_Star",
"Prims.unit",
"Lib.NatMod.pow",
"Lib.Exponentiation.Definition.lemma_pow_mul",
"Lib.Exponentiation.Definition.comm_monoid",
"Lib.NatMod.mk_nat_comm_monoid"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m)) | [] | Lib.NatMod.lemma_pow_mul | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Prims.int -> n: Prims.nat -> m: Prims.nat
-> FStar.Pervasives.Lemma
(ensures Lib.NatMod.pow (Lib.NatMod.pow x n) m = Lib.NatMod.pow x (n * m)) | {
"end_col": 32,
"end_line": 64,
"start_col": 25,
"start_line": 59
} |
FStar.Pervasives.Lemma | val lemma_mod_distributivity_sub_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (sub_mod a b) c == sub_mod (mul_mod a c) (mul_mod b c)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b | val lemma_mod_distributivity_sub_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (sub_mod a b) c == sub_mod (mul_mod a c) (mul_mod b c))
let lemma_mod_distributivity_sub_left #m a b c = | false | null | true | lemma_mod_distributivity_sub_right c a b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"Lib.NatMod.lemma_mod_distributivity_sub_right",
"Prims.unit"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
} | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mod_distributivity_sub_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (sub_mod a b) c == sub_mod (mul_mod a c) (mul_mod b c)) | [] | Lib.NatMod.lemma_mod_distributivity_sub_left | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.mul_mod (Lib.NatMod.sub_mod a b) c ==
Lib.NatMod.sub_mod (Lib.NatMod.mul_mod a c) (Lib.NatMod.mul_mod b c)) | {
"end_col": 42,
"end_line": 264,
"start_col": 2,
"start_line": 264
} |
FStar.Pervasives.Lemma | val lemma_pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> Lemma (pow a b % m == pow_mod #m a b) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_pow_mod #n a b = lemma_pow_mod_ n a b | val lemma_pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> Lemma (pow a b % m == pow_mod #m a b)
let lemma_pow_mod #n a b = | false | null | true | lemma_pow_mod_ n a b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Prims.nat",
"Lib.NatMod.lemma_pow_mod_",
"Prims.unit"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> Lemma (pow a b % m == pow_mod #m a b) | [] | Lib.NatMod.lemma_pow_mod | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Prims.nat
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b % m == Lib.NatMod.pow_mod a b) | {
"end_col": 47,
"end_line": 186,
"start_col": 27,
"start_line": 186
} |
FStar.Pervasives.Lemma | val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1) | val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n = | false | null | true | if n = 0 then () else pow_eq a (n - 1) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Lib.NatMod.pow_eq",
"Prims.op_Subtraction",
"Prims.unit"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) | [
"recursion"
] | Lib.NatMod.pow_eq | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.nat -> n: Prims.nat
-> FStar.Pervasives.Lemma (ensures FStar.Math.Fermat.pow a n == Lib.NatMod.pow a n) | {
"end_col": 23,
"end_line": 292,
"start_col": 2,
"start_line": 291
} |
FStar.Pervasives.Lemma | val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)] | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end | val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
let rec lemma_pow_ge_zero a b = | false | null | true | if b = 0
then lemma_pow0 a
else
(lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1)) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Lib.NatMod.lemma_pow0",
"Prims.bool",
"Lib.NatMod.lemma_pow_ge_zero",
"Prims.op_Subtraction",
"Prims.unit",
"Lib.NatMod.lemma_pow_unfold"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)] | [
"recursion"
] | Lib.NatMod.lemma_pow_ge_zero | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.nat -> b: Prims.nat
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b >= 0) [SMTPat (Lib.NatMod.pow a b)] | {
"end_col": 35,
"end_line": 26,
"start_col": 2,
"start_line": 23
} |
FStar.Pervasives.Lemma | val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end | val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
let rec lemma_pow_nat_is_pow a b = | false | null | true | let k = mk_nat_comm_monoid in
if b = 0
then
(lemma_pow0 a;
LE.lemma_pow0 k a)
else
(lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
()) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.nat",
"Prims.op_Equality",
"Lib.Exponentiation.Definition.lemma_pow0",
"Prims.unit",
"Lib.NatMod.lemma_pow0",
"Prims.bool",
"Lib.Exponentiation.Definition.lemma_pow_unfold",
"Lib.NatMod.lemma_pow_nat_is_pow",
"Prims.op_Subtraction",
"Lib.NatMod.lemma_pow_unfold",
"Lib.Exponentiation.Definition.comm_monoid",
"Lib.NatMod.mk_nat_comm_monoid"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_nat_is_pow: a:int -> b:nat ->
Lemma (pow a b == LE.pow mk_nat_comm_monoid a b) | [
"recursion"
] | Lib.NatMod.lemma_pow_nat_is_pow | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.int -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.pow a b == Lib.Exponentiation.Definition.pow Lib.NatMod.mk_nat_comm_monoid a b) | {
"end_col": 10,
"end_line": 38,
"start_col": 34,
"start_line": 29
} |
FStar.Pervasives.Lemma | val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b | val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
let lemma_pow_one b = | false | null | true | let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.nat",
"Lib.NatMod.lemma_pow_nat_is_pow",
"Prims.unit",
"Lib.Exponentiation.Definition.lemma_pow_one",
"Prims.int",
"Lib.Exponentiation.Definition.comm_monoid",
"Lib.NatMod.mk_nat_comm_monoid"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1) | [] | Lib.NatMod.lemma_pow_one | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow 1 b = 1) | {
"end_col": 26,
"end_line": 48,
"start_col": 21,
"start_line": 45
} |
FStar.Pervasives.Lemma | val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)] | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end | val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
let rec lemma_pow_gt_zero a b = | false | null | true | if b = 0
then lemma_pow0 a
else
(lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1)) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Lib.NatMod.lemma_pow0",
"Prims.bool",
"Lib.NatMod.lemma_pow_gt_zero",
"Prims.op_Subtraction",
"Prims.unit",
"Lib.NatMod.lemma_pow_unfold"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)] | [
"recursion"
] | Lib.NatMod.lemma_pow_gt_zero | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.pos -> b: Prims.nat
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b > 0) [SMTPat (Lib.NatMod.pow a b)] | {
"end_col": 35,
"end_line": 19,
"start_col": 2,
"start_line": 16
} |
FStar.Pervasives.Lemma | val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires div_mod a b = 0)
(ensures a = 0 || b = 0) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_prime_is_zero2 #m a b =
lemma_mul_mod_prime_zero a (inv_mod b);
assert (a = 0 || inv_mod b = 0);
lemma_pow_mod_prime_zero #m b (m - 2) | val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires div_mod a b = 0)
(ensures a = 0 || b = 0)
let lemma_div_mod_prime_is_zero2 #m a b = | false | null | true | lemma_mul_mod_prime_zero a (inv_mod b);
assert (a = 0 || inv_mod b = 0);
lemma_pow_mod_prime_zero #m b (m - 2) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Lib.NatMod.lemma_pow_mod_prime_zero",
"Prims.op_Subtraction",
"Prims.unit",
"Prims._assert",
"Prims.op_BarBar",
"Prims.op_Equality",
"Prims.int",
"Lib.NatMod.inv_mod",
"Lib.NatMod.lemma_mul_mod_prime_zero"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else ()
let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0)
let lemma_mul_mod_zero2 n x y =
if x % n = 0 then
Math.Lemmas.lemma_mod_mul_distr_l x y n
else
Math.Lemmas.lemma_mod_mul_distr_r x y n
let lemma_mul_mod_prime_zero #m a b =
Classical.move_requires_3 Euclid.euclid_prime m a b;
Classical.move_requires_3 lemma_mul_mod_zero2 m a b
val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma
(requires pow a b % m = 0)
(ensures a = 0)
let rec lemma_pow_mod_prime_zero_ #m a b =
if b = 1 then lemma_pow1 a
else begin
let r1 = pow a (b - 1) % m in
lemma_pow_unfold a b;
assert (a * pow a (b - 1) % m = 0);
Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m;
lemma_mul_mod_prime_zero #m a r1;
//assert (a = 0 \/ r1 = 0);
if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end
let lemma_pow_mod_prime_zero #m a b =
lemma_pow_mod #m a b;
Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b;
Classical.move_requires lemma_pow_zero b
val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires a = 0 || b = 0)
(ensures div_mod a b = 0)
let lemma_div_mod_is_zero1 #m a b =
if a = 0 then ()
else begin
lemma_pow_mod #m b (m - 2);
lemma_pow_zero (m - 2) end
val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires div_mod a b = 0)
(ensures a = 0 || b = 0) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires div_mod a b = 0)
(ensures a = 0 || b = 0) | [] | Lib.NatMod.lemma_div_mod_prime_is_zero2 | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma (requires Lib.NatMod.div_mod a b = 0) (ensures a = 0 || b = 0) | {
"end_col": 39,
"end_line": 457,
"start_col": 2,
"start_line": 455
} |
FStar.Pervasives.Lemma | val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_pow_zero b =
lemma_pow_unfold 0 b | val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
let lemma_pow_zero b = | false | null | true | lemma_pow_unfold 0 b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Lib.NatMod.lemma_pow_unfold",
"Prims.unit"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0) | [] | Lib.NatMod.lemma_pow_zero | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Prims.pos -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow 0 b = 0) | {
"end_col": 22,
"end_line": 42,
"start_col": 2,
"start_line": 42
} |
FStar.Pervasives.Lemma | val lemma_div_mod_eq_mul_mod: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma ((div_mod a b = c) == (a = mul_mod c b)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c | val lemma_div_mod_eq_mul_mod: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma ((div_mod a b = c) == (a = mul_mod c b))
let lemma_div_mod_eq_mul_mod #m a b c = | false | null | true | lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Lib.NatMod.nat_mod",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"Lib.NatMod.lemma_div_mod_eq_mul_mod2",
"Prims.unit",
"Lib.NatMod.lemma_div_mod_eq_mul_mod1"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else () | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_eq_mul_mod: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma ((div_mod a b = c) == (a = mul_mod c b)) | [] | Lib.NatMod.lemma_div_mod_eq_mul_mod | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m {b <> 0} -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a b = c == (a = Lib.NatMod.mul_mod c b)) | {
"end_col": 33,
"end_line": 399,
"start_col": 2,
"start_line": 398
} |
FStar.Pervasives.Lemma | val lemma_div_mod_prime_is_zero: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m ->
Lemma ((div_mod a b = 0) <==> (a = 0 || b = 0)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_prime_is_zero #m a b =
Classical.move_requires_2 lemma_div_mod_is_zero1 a b;
Classical.move_requires_2 lemma_div_mod_prime_is_zero2 a b | val lemma_div_mod_prime_is_zero: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m ->
Lemma ((div_mod a b = 0) <==> (a = 0 || b = 0))
let lemma_div_mod_prime_is_zero #m a b = | false | null | true | Classical.move_requires_2 lemma_div_mod_is_zero1 a b;
Classical.move_requires_2 lemma_div_mod_prime_is_zero2 a b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"FStar.Classical.move_requires_2",
"Prims.op_Equality",
"Prims.int",
"Lib.NatMod.div_mod",
"Prims.op_BarBar",
"Lib.NatMod.lemma_div_mod_prime_is_zero2",
"Prims.unit",
"Lib.NatMod.lemma_div_mod_is_zero1"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else ()
let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0)
let lemma_mul_mod_zero2 n x y =
if x % n = 0 then
Math.Lemmas.lemma_mod_mul_distr_l x y n
else
Math.Lemmas.lemma_mod_mul_distr_r x y n
let lemma_mul_mod_prime_zero #m a b =
Classical.move_requires_3 Euclid.euclid_prime m a b;
Classical.move_requires_3 lemma_mul_mod_zero2 m a b
val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma
(requires pow a b % m = 0)
(ensures a = 0)
let rec lemma_pow_mod_prime_zero_ #m a b =
if b = 1 then lemma_pow1 a
else begin
let r1 = pow a (b - 1) % m in
lemma_pow_unfold a b;
assert (a * pow a (b - 1) % m = 0);
Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m;
lemma_mul_mod_prime_zero #m a r1;
//assert (a = 0 \/ r1 = 0);
if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end
let lemma_pow_mod_prime_zero #m a b =
lemma_pow_mod #m a b;
Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b;
Classical.move_requires lemma_pow_zero b
val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires a = 0 || b = 0)
(ensures div_mod a b = 0)
let lemma_div_mod_is_zero1 #m a b =
if a = 0 then ()
else begin
lemma_pow_mod #m b (m - 2);
lemma_pow_zero (m - 2) end
val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires div_mod a b = 0)
(ensures a = 0 || b = 0)
let lemma_div_mod_prime_is_zero2 #m a b =
lemma_mul_mod_prime_zero a (inv_mod b);
assert (a = 0 || inv_mod b = 0);
lemma_pow_mod_prime_zero #m b (m - 2) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_prime_is_zero: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m ->
Lemma ((div_mod a b = 0) <==> (a = 0 || b = 0)) | [] | Lib.NatMod.lemma_div_mod_prime_is_zero | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a b = 0 <==> a = 0 || b = 0) | {
"end_col": 60,
"end_line": 462,
"start_col": 2,
"start_line": 461
} |
FStar.Pervasives.Lemma | val lemma_add_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (add_mod (add_mod a b) c == add_mod a (add_mod b c)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
} | val lemma_add_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (add_mod (add_mod a b) c == add_mod a (add_mod b c))
let lemma_add_mod_assoc #m a b c = | false | null | true | calc ( == ) {
add_mod (add_mod a b) c;
( == ) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
( == ) { () }
(a + (b + c)) % m;
( == ) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
} | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Lib.NatMod.add_mod",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_plus_distr_r"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_add_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (add_mod (add_mod a b) c == add_mod a (add_mod b c)) | [] | Lib.NatMod.lemma_add_mod_assoc | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.add_mod (Lib.NatMod.add_mod a b) c == Lib.NatMod.add_mod a (Lib.NatMod.add_mod b c)
) | {
"end_col": 3,
"end_line": 223,
"start_col": 2,
"start_line": 215
} |
FStar.Pervasives.Lemma | val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m) | val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
let lemma_pow_add x n m = | false | null | true | let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.nat",
"Lib.NatMod.lemma_pow_nat_is_pow",
"Prims.op_Addition",
"Prims.unit",
"Lib.Exponentiation.Definition.lemma_pow_add",
"Lib.Exponentiation.Definition.comm_monoid",
"Lib.NatMod.mk_nat_comm_monoid"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m)) | [] | Lib.NatMod.lemma_pow_add | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Prims.int -> n: Prims.nat -> m: Prims.nat
-> FStar.Pervasives.Lemma
(ensures Lib.NatMod.pow x n * Lib.NatMod.pow x m = Lib.NatMod.pow x (n + m)) | {
"end_col": 32,
"end_line": 56,
"start_col": 25,
"start_line": 51
} |
FStar.Pervasives.Lemma | val lemma_add_mod_one: #m:pos -> a:nat_mod m -> Lemma (add_mod a 0 == a) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m | val lemma_add_mod_one: #m:pos -> a:nat_mod m -> Lemma (add_mod a 0 == a)
let lemma_add_mod_one #m a = | false | null | true | Math.Lemmas.small_mod a m | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"FStar.Math.Lemmas.small_mod",
"Prims.unit"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_add_mod_one: #m:pos -> a:nat_mod m -> Lemma (add_mod a 0 == a) | [] | Lib.NatMod.lemma_add_mod_one | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.add_mod a 0 == a) | {
"end_col": 27,
"end_line": 211,
"start_col": 2,
"start_line": 211
} |
FStar.Pervasives.Lemma | val lemma_mul_mod_prime_zero: #m:prime -> a:nat_mod m -> b:nat_mod m ->
Lemma (a * b % m == 0 <==> (a % m == 0 \/ b % m == 0)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_mul_mod_prime_zero #m a b =
Classical.move_requires_3 Euclid.euclid_prime m a b;
Classical.move_requires_3 lemma_mul_mod_zero2 m a b | val lemma_mul_mod_prime_zero: #m:prime -> a:nat_mod m -> b:nat_mod m ->
Lemma (a * b % m == 0 <==> (a % m == 0 \/ b % m == 0))
let lemma_mul_mod_prime_zero #m a b = | false | null | true | Classical.move_requires_3 Euclid.euclid_prime m a b;
Classical.move_requires_3 lemma_mul_mod_zero2 m a b | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Lib.NatMod.nat_mod",
"FStar.Classical.move_requires_3",
"Prims.pos",
"Prims.int",
"Prims.l_or",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Lib.NatMod.lemma_mul_mod_zero2",
"Prims.unit",
"FStar.Math.Euclid.is_prime",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Math.Euclid.euclid_prime"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else ()
let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0)
let lemma_mul_mod_zero2 n x y =
if x % n = 0 then
Math.Lemmas.lemma_mod_mul_distr_l x y n
else
Math.Lemmas.lemma_mod_mul_distr_r x y n | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mul_mod_prime_zero: #m:prime -> a:nat_mod m -> b:nat_mod m ->
Lemma (a * b % m == 0 <==> (a % m == 0 \/ b % m == 0)) | [] | Lib.NatMod.lemma_mul_mod_prime_zero | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma (ensures a * b % m == 0 <==> a % m == 0 \/ b % m == 0) | {
"end_col": 53,
"end_line": 415,
"start_col": 2,
"start_line": 414
} |
FStar.Pervasives.Lemma | val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires a = 0 || b = 0)
(ensures div_mod a b = 0) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_is_zero1 #m a b =
if a = 0 then ()
else begin
lemma_pow_mod #m b (m - 2);
lemma_pow_zero (m - 2) end | val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires a = 0 || b = 0)
(ensures div_mod a b = 0)
let lemma_div_mod_is_zero1 #m a b = | false | null | true | if a = 0
then ()
else
(lemma_pow_mod #m b (m - 2);
lemma_pow_zero (m - 2)) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Lib.NatMod.lemma_pow_zero",
"Prims.op_Subtraction",
"Prims.unit",
"Lib.NatMod.lemma_pow_mod"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else ()
let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0)
let lemma_mul_mod_zero2 n x y =
if x % n = 0 then
Math.Lemmas.lemma_mod_mul_distr_l x y n
else
Math.Lemmas.lemma_mod_mul_distr_r x y n
let lemma_mul_mod_prime_zero #m a b =
Classical.move_requires_3 Euclid.euclid_prime m a b;
Classical.move_requires_3 lemma_mul_mod_zero2 m a b
val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma
(requires pow a b % m = 0)
(ensures a = 0)
let rec lemma_pow_mod_prime_zero_ #m a b =
if b = 1 then lemma_pow1 a
else begin
let r1 = pow a (b - 1) % m in
lemma_pow_unfold a b;
assert (a * pow a (b - 1) % m = 0);
Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m;
lemma_mul_mod_prime_zero #m a r1;
//assert (a = 0 \/ r1 = 0);
if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end
let lemma_pow_mod_prime_zero #m a b =
lemma_pow_mod #m a b;
Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b;
Classical.move_requires lemma_pow_zero b
val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires a = 0 || b = 0)
(ensures div_mod a b = 0) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma
(requires a = 0 || b = 0)
(ensures div_mod a b = 0) | [] | Lib.NatMod.lemma_div_mod_is_zero1 | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma (requires a = 0 || b = 0) (ensures Lib.NatMod.div_mod a b = 0) | {
"end_col": 30,
"end_line": 448,
"start_col": 2,
"start_line": 445
} |
FStar.Pervasives.Lemma | val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else () | val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c = | false | null | true | if a = mul_mod c b
then
(assert (div_mod a b == div_mod (mul_mod c b) b);
calc ( == ) {
div_mod (mul_mod c b) b;
( == ) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
( == ) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
( == ) { lemma_div_mod_prime_one c }
c;
}) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Lib.NatMod.nat_mod",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"Prims.op_Equality",
"Lib.NatMod.mul_mod",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Lib.NatMod.div_mod",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.small_mod",
"Prims.squash",
"Lib.NatMod.lemma_div_mod_prime_cancel",
"Lib.NatMod.lemma_div_mod_prime_one",
"Prims._assert",
"Prims.bool"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c) | [] | Lib.NatMod.lemma_div_mod_eq_mul_mod2 | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m {b <> 0} -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma (ensures a = Lib.NatMod.mul_mod c b ==> Lib.NatMod.div_mod a b = c) | {
"end_col": 9,
"end_line": 394,
"start_col": 2,
"start_line": 383
} |
FStar.Pervasives.Lemma | val lemma_mod_distributivity_add_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod a (add_mod b c) == add_mod (mul_mod a b) (mul_mod a c)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
} | val lemma_mod_distributivity_add_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod a (add_mod b c) == add_mod (mul_mod a b) (mul_mod a c))
let lemma_mod_distributivity_add_right #m a b c = | false | null | true | calc ( == ) {
mul_mod a (add_mod b c);
( == ) { () }
a * ((b + c) % m) % m;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
( == ) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
( == ) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
} | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Lib.NatMod.mul_mod",
"Lib.NatMod.add_mod",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"FStar.Math.Lemmas.distributivity_add_right",
"FStar.Math.Lemmas.modulo_distributivity"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = () | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mod_distributivity_add_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod a (add_mod b c) == add_mod (mul_mod a b) (mul_mod a c)) | [] | Lib.NatMod.lemma_mod_distributivity_add_right | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.mul_mod a (Lib.NatMod.add_mod b c) ==
Lib.NatMod.add_mod (Lib.NatMod.mul_mod a b) (Lib.NatMod.mul_mod a c)) | {
"end_col": 5,
"end_line": 240,
"start_col": 2,
"start_line": 230
} |
FStar.Pervasives.Lemma | val lemma_mul_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (mul_mod a b) c == mul_mod a (mul_mod b c)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
} | val lemma_mul_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (mul_mod a b) c == mul_mod a (mul_mod b c))
let lemma_mul_mod_assoc #m a b c = | false | null | true | calc ( == ) {
(a * b % m) * c % m;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
( == ) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
} | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims.squash",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = () | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mul_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod (mul_mod a b) c == mul_mod a (mul_mod b c)) | [] | Lib.NatMod.lemma_mul_mod_assoc | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.mul_mod (Lib.NatMod.mul_mod a b) c == Lib.NatMod.mul_mod a (Lib.NatMod.mul_mod b c)
) | {
"end_col": 5,
"end_line": 118,
"start_col": 2,
"start_line": 110
} |
FStar.Pervasives.Lemma | val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_mul_mod_zero2 n x y =
if x % n = 0 then
Math.Lemmas.lemma_mod_mul_distr_l x y n
else
Math.Lemmas.lemma_mod_mul_distr_r x y n | val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0)
let lemma_mul_mod_zero2 n x y = | false | null | true | if x % n = 0
then Math.Lemmas.lemma_mod_mul_distr_l x y n
else Math.Lemmas.lemma_mod_mul_distr_r x y n | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.int",
"Prims.op_Equality",
"Prims.op_Modulus",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims.bool",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Prims.unit"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else ()
let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0) | [] | Lib.NatMod.lemma_mul_mod_zero2 | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | n: Prims.pos -> x: Prims.int -> y: Prims.int
-> FStar.Pervasives.Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0) | {
"end_col": 43,
"end_line": 410,
"start_col": 2,
"start_line": 407
} |
FStar.Pervasives.Lemma | val lemma_div_mod_prime_to_one_denominator:
#m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} -> d:nat_mod m{d <> 0} ->
Lemma (mul_mod (div_mod a c) (div_mod b d) == div_mod (mul_mod a b) (mul_mod c d)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
} | val lemma_div_mod_prime_to_one_denominator:
#m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} -> d:nat_mod m{d <> 0} ->
Lemma (mul_mod (div_mod a c) (div_mod b d) == div_mod (mul_mod a b) (mul_mod c d))
let lemma_div_mod_prime_to_one_denominator #m a b c d = | false | null | true | calc ( == ) {
mul_mod (div_mod a c) (div_mod b d);
( == ) { () }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
( == ) { (lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b) }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
( == ) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
( == ) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
( == ) { (lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d))) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
} | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Prims.op_disEquality",
"Prims.int",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Lib.NatMod.mul_mod",
"Lib.NatMod.div_mod",
"Lib.NatMod.inv_mod",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Lib.NatMod.lemma_mul_mod_assoc",
"Lib.NatMod.lemma_mul_mod_comm",
"Lib.NatMod.lemma_inv_mod_both"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
} | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_prime_to_one_denominator:
#m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} -> d:nat_mod m{d <> 0} ->
Lemma (mul_mod (div_mod a c) (div_mod b d) == div_mod (mul_mod a b) (mul_mod c d)) | [] | Lib.NatMod.lemma_div_mod_prime_to_one_denominator | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Lib.NatMod.nat_mod m ->
b: Lib.NatMod.nat_mod m ->
c: Lib.NatMod.nat_mod m {c <> 0} ->
d: Lib.NatMod.nat_mod m {d <> 0}
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.mul_mod (Lib.NatMod.div_mod a c) (Lib.NatMod.div_mod b d) ==
Lib.NatMod.div_mod (Lib.NatMod.mul_mod a b) (Lib.NatMod.mul_mod c d)) | {
"end_col": 5,
"end_line": 356,
"start_col": 2,
"start_line": 339
} |
FStar.Pervasives.Lemma | val lemma_mod_distributivity_sub_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod a (sub_mod b c) == sub_mod (mul_mod a b) (mul_mod a c)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
} | val lemma_mod_distributivity_sub_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod a (sub_mod b c) == sub_mod (mul_mod a b) (mul_mod a c))
let lemma_mod_distributivity_sub_right #m a b c = | false | null | true | calc ( == ) {
mul_mod a (sub_mod b c);
( == ) { () }
a * ((b - c) % m) % m;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
( == ) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
( == ) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
( == ) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
} | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Lib.NatMod.nat_mod",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Lib.NatMod.mul_mod",
"Lib.NatMod.sub_mod",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Modulus",
"Prims.op_Subtraction",
"FStar.Mul.op_Star",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"FStar.Math.Lemmas.distributivity_sub_right",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Prims.op_Minus",
"FStar.Math.Lemmas.lemma_mod_sub_distr"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_mod_distributivity_sub_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m ->
Lemma (mul_mod a (sub_mod b c) == sub_mod (mul_mod a b) (mul_mod a c)) | [] | Lib.NatMod.lemma_mod_distributivity_sub_right | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.mul_mod a (Lib.NatMod.sub_mod b c) ==
Lib.NatMod.sub_mod (Lib.NatMod.mul_mod a b) (Lib.NatMod.mul_mod a c)) | {
"end_col": 5,
"end_line": 260,
"start_col": 2,
"start_line": 248
} |
FStar.Pervasives.Lemma | val lemma_div_mod_prime_one: #m:pos{1 < m} -> a:nat_mod m -> Lemma (div_mod a 1 == a) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m | val lemma_div_mod_prime_one: #m:pos{1 < m} -> a:nat_mod m -> Lemma (div_mod a 1 == a)
let lemma_div_mod_prime_one #m a = | false | null | true | lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"FStar.Math.Lemmas.small_mod",
"Prims.unit",
"Lib.NatMod.lemma_pow_one",
"Prims.op_Subtraction",
"Lib.NatMod.lemma_pow_mod"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
} | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_prime_one: #m:pos{1 < m} -> a:nat_mod m -> Lemma (div_mod a 1 == a) | [] | Lib.NatMod.lemma_div_mod_prime_one | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a 1 == a) | {
"end_col": 27,
"end_line": 319,
"start_col": 2,
"start_line": 317
} |
FStar.Pervasives.Lemma | val lemma_inv_mod_both: #m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m ->
Lemma (inv_mod (mul_mod a b) == mul_mod (inv_mod a) (inv_mod b)) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
} | val lemma_inv_mod_both: #m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m ->
Lemma (inv_mod (mul_mod a b) == mul_mod (inv_mod a) (inv_mod b))
let lemma_inv_mod_both #m a b = | false | null | true | let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc ( == ) {
mul_mod (inv_mod a) (inv_mod b);
( == ) { (lemma_pow_mod #m a (m - 2);
lemma_pow_mod #m b (m - 2)) }
(p1 % m) * (p2 % m) % m;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
( == ) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
( == ) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
( == ) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
} | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Lib.NatMod.mul_mod",
"Lib.NatMod.inv_mod",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Prims.op_Subtraction",
"FStar.Mul.op_Star",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.NatMod.lemma_pow_mod",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Lib.NatMod.lemma_pow_mul_base",
"Lib.NatMod.lemma_pow_mod_base",
"Prims.int"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_inv_mod_both: #m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m ->
Lemma (inv_mod (mul_mod a b) == mul_mod (inv_mod a) (inv_mod b)) | [] | Lib.NatMod.lemma_inv_mod_both | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.inv_mod (Lib.NatMod.mul_mod a b) ==
Lib.NatMod.mul_mod (Lib.NatMod.inv_mod a) (Lib.NatMod.inv_mod b)) | {
"end_col": 5,
"end_line": 285,
"start_col": 31,
"start_line": 267
} |
FStar.Pervasives.Lemma | val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else () | val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c = | false | null | true | if div_mod a b = c
then
(assert (mul_mod (div_mod a b) b = mul_mod c b);
calc ( == ) {
mul_mod (div_mod a b) b;
( == ) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
( == ) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
( == ) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
( == ) { lemma_div_mod_prime_one a }
a;
}) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Lib.NatMod.nat_mod",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"Prims.op_Equality",
"Lib.NatMod.div_mod",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Lib.NatMod.mul_mod",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.NatMod.lemma_div_mod_prime_one",
"Prims.squash",
"Lib.NatMod.lemma_div_mod_prime_to_one_denominator",
"Lib.NatMod.lemma_div_mod_prime_cancel",
"Prims._assert",
"Prims.bool"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b) | [] | Lib.NatMod.lemma_div_mod_eq_mul_mod1 | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m {b <> 0} -> c: Lib.NatMod.nat_mod m
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a b = c ==> a = Lib.NatMod.mul_mod c b) | {
"end_col": 9,
"end_line": 376,
"start_col": 2,
"start_line": 363
} |
FStar.Pervasives.Lemma | val lemma_div_mod_prime_cancel: #m:prime -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} ->
Lemma (div_mod (mul_mod a c) (mul_mod c b) == div_mod a b) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
} | val lemma_div_mod_prime_cancel: #m:prime -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} ->
Lemma (div_mod (mul_mod a c) (mul_mod c b) == div_mod a b)
let lemma_div_mod_prime_cancel #m a b c = | false | null | true | calc ( == ) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
( == ) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
( == ) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
( == ) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
( == ) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
( == ) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
} | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Lib.NatMod.nat_mod",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Lib.NatMod.mul_mod",
"Lib.NatMod.inv_mod",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.NatMod.lemma_inv_mod_both",
"Prims.squash",
"Lib.NatMod.lemma_mul_mod_assoc",
"Lib.NatMod.lemma_div_mod_prime",
"FStar.Math.Lemmas.small_mod"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_prime_cancel: #m:prime -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} ->
Lemma (div_mod (mul_mod a c) (mul_mod c b) == div_mod a b) | [] | Lib.NatMod.lemma_div_mod_prime_cancel | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m {c <> 0}
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.div_mod (Lib.NatMod.mul_mod a c) (Lib.NatMod.mul_mod c b) == Lib.NatMod.div_mod a b
) | {
"end_col": 5,
"end_line": 335,
"start_col": 2,
"start_line": 323
} |
FStar.Pervasives.Lemma | val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end | val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
let rec lemma_pow_mod_base a b n = | false | null | true | if b = 0
then
(lemma_pow0 a;
lemma_pow0 (a % n))
else
(calc ( == ) {
pow a b % n;
( == ) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
( == ) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
(a % n) * pow (a % n) (b - 1) % n;
( == ) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.int",
"Prims.nat",
"Prims.pos",
"Prims.op_Equality",
"Lib.NatMod.lemma_pow0",
"Prims.op_Modulus",
"Prims.unit",
"Prims.bool",
"Prims._assert",
"Prims.eq2",
"Lib.NatMod.pow",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.NatMod.lemma_pow_unfold",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Lib.NatMod.lemma_pow_mod_base",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n) | [
"recursion"
] | Lib.NatMod.lemma_pow_mod_base | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Prims.int -> b: Prims.nat -> n: Prims.pos
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b % n == Lib.NatMod.pow (a % n) b % n) | {
"end_col": 5,
"end_line": 103,
"start_col": 2,
"start_line": 83
} |
FStar.Pervasives.Lemma | val lemma_pow_nat_mod_is_pow: #n:pos{1 < n} -> a:nat_mod n -> b:nat ->
Lemma (pow a b % n == LE.pow (mk_nat_mod_comm_monoid n) a b) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end | val lemma_pow_nat_mod_is_pow: #n:pos{1 < n} -> a:nat_mod n -> b:nat ->
Lemma (pow a b % n == LE.pow (mk_nat_mod_comm_monoid n) a b)
let rec lemma_pow_nat_mod_is_pow #n a b = | false | null | true | let k = mk_nat_mod_comm_monoid n in
if b = 0
then
(lemma_pow0 a;
LE.lemma_pow0 k a)
else
(calc ( == ) {
pow a b % n;
( == ) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
( == ) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
( == ) { () }
k.LE.mul a (LE.pow k a (b - 1));
( == ) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
};
()) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Lib.Exponentiation.Definition.lemma_pow0",
"Prims.unit",
"Lib.NatMod.lemma_pow0",
"Prims.bool",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Lib.Exponentiation.Definition.pow",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Lib.Exponentiation.Definition.__proj__Mkcomm_monoid__item__mul",
"Prims.op_Subtraction",
"FStar.Mul.op_Star",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.NatMod.lemma_pow_unfold",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Lib.NatMod.lemma_pow_nat_mod_is_pow",
"Lib.Exponentiation.Definition.lemma_pow_unfold",
"Lib.Exponentiation.Definition.comm_monoid",
"Lib.NatMod.mk_nat_mod_comm_monoid"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_nat_mod_is_pow: #n:pos{1 < n} -> a:nat_mod n -> b:nat ->
Lemma (pow a b % n == LE.pow (mk_nat_mod_comm_monoid n) a b) | [
"recursion"
] | Lib.NatMod.lemma_pow_nat_mod_is_pow | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod n -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.pow a b % n ==
Lib.Exponentiation.Definition.pow (Lib.NatMod.mk_nat_mod_comm_monoid n) a b) | {
"end_col": 15,
"end_line": 207,
"start_col": 41,
"start_line": 189
} |
FStar.Pervasives.Lemma | val lemma_div_mod_prime: #m:prime -> a:nat_mod m{a <> 0} -> Lemma (div_mod a a == 1) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
} | val lemma_div_mod_prime: #m:prime -> a:nat_mod m{a <> 0} -> Lemma (div_mod a a == 1)
let lemma_div_mod_prime #m a = | false | null | true | Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc ( == ) {
pow_mod #m a (m - 2) * a % m;
( == ) { lemma_pow_mod #m a (m - 2) }
(pow a (m - 2) % m) * a % m;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
( == ) { (lemma_pow1 a;
lemma_pow_add a (m - 2) 1) }
pow a (m - 1) % m;
( == ) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
( == ) { Fermat.fermat_alt m a }
1;
} | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Lib.NatMod.nat_mod",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Lib.NatMod.pow_mod",
"Prims.op_Subtraction",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Math.Fermat.pow",
"Lib.NatMod.pow",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.NatMod.lemma_pow_mod",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Lib.NatMod.lemma_pow_add",
"Lib.NatMod.lemma_pow1",
"Lib.NatMod.pow_eq",
"FStar.Math.Fermat.fermat_alt",
"Prims._assert",
"Prims.l_and",
"FStar.Math.Lemmas.small_mod"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_div_mod_prime: #m:prime -> a:nat_mod m{a <> 0} -> Lemma (div_mod a a == 1) | [] | Lib.NatMod.lemma_div_mod_prime | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m {a <> 0} -> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a a == 1) | {
"end_col": 5,
"end_line": 313,
"start_col": 2,
"start_line": 297
} |
FStar.Pervasives.Lemma | val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end | val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b = | false | null | true | if b = 0
then
(lemma_pow0 a;
lemma_pow_mod0 a)
else
if b % 2 = 0
then
(calc ( == ) {
pow_mod #n a b;
( == ) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
( == ) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
( == ) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
( == ) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n))
else
(calc ( == ) {
pow_mod #n a b;
( == ) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
( == ) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
( == ) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
( == ) { lemma_pow_double a (b / 2) }
mul_mod a (pow a ((b / 2) * 2) % n);
( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a ((b / 2) * 2)) n }
a * pow a ((b / 2) * 2) % n;
( == ) { lemma_pow1 a }
pow a 1 * pow a ((b / 2) * 2) % n;
( == ) { lemma_pow_add a 1 ((b / 2) * 2) }
pow a ((b / 2) * 2 + 1) % n;
( == ) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n)) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma",
""
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.NatMod.nat_mod",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Lib.NatMod.lemma_pow_mod0",
"Prims.unit",
"Lib.NatMod.lemma_pow0",
"Prims.bool",
"Prims.op_Modulus",
"Prims._assert",
"Prims.eq2",
"Lib.NatMod.pow_mod",
"Lib.NatMod.pow",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Lib.NatMod.mul_mod",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.NatMod.lemma_pow_mod_unfold0",
"Prims.squash",
"Lib.NatMod.lemma_pow_mod_",
"Lib.NatMod.lemma_pow_mod_base",
"Lib.NatMod.lemma_pow_double",
"Prims.op_Addition",
"Lib.NatMod.lemma_pow_mod_unfold1",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Lib.NatMod.lemma_pow1",
"Lib.NatMod.lemma_pow_add",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b) | [
"recursion"
] | Lib.NatMod.lemma_pow_mod_ | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | n: Prims.pos{1 < n} -> a: Lib.NatMod.nat_mod n -> b: Prims.nat
-> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow_mod a b == Lib.NatMod.pow a b % n) (decreases b) | {
"end_col": 5,
"end_line": 184,
"start_col": 2,
"start_line": 146
} |
FStar.Pervasives.Lemma | val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma
(requires pow a b % m = 0)
(ensures a = 0) | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Math.Euclid",
"short_module": "Euclid"
},
{
"abbrev": true,
"full_module": "FStar.Math.Fermat",
"short_module": "Fermat"
},
{
"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
}
] | false | let rec lemma_pow_mod_prime_zero_ #m a b =
if b = 1 then lemma_pow1 a
else begin
let r1 = pow a (b - 1) % m in
lemma_pow_unfold a b;
assert (a * pow a (b - 1) % m = 0);
Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m;
lemma_mul_mod_prime_zero #m a r1;
//assert (a = 0 \/ r1 = 0);
if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end | val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma
(requires pow a b % m = 0)
(ensures a = 0)
let rec lemma_pow_mod_prime_zero_ #m a b = | false | null | true | if b = 1
then lemma_pow1 a
else
let r1 = pow a (b - 1) % m in
lemma_pow_unfold a b;
assert (a * pow a (b - 1) % m = 0);
Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m;
lemma_mul_mod_prime_zero #m a r1;
if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) | {
"checked_file": "Lib.NatMod.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Lib.NatMod.fst"
} | [
"lemma"
] | [
"Lib.NatMod.prime",
"Lib.NatMod.nat_mod",
"Prims.pos",
"Prims.op_Equality",
"Prims.int",
"Lib.NatMod.lemma_pow1",
"Prims.bool",
"Lib.NatMod.lemma_pow_mod_prime_zero_",
"Prims.op_Subtraction",
"Prims.unit",
"Lib.NatMod.lemma_mul_mod_prime_zero",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Lib.NatMod.pow",
"Prims._assert",
"Prims.b2t",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Lib.NatMod.lemma_pow_unfold"
] | [] | module Lib.NatMod
module LE = Lib.Exponentiation.Definition
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
#push-options "--fuel 2"
let lemma_pow0 a = ()
let lemma_pow1 a = ()
let lemma_pow_unfold a b = ()
#pop-options
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_gt_zero a (b - 1) end
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a
else begin
lemma_pow_unfold a b;
lemma_pow_ge_zero a (b - 1) end
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
lemma_pow_unfold a b;
lemma_pow_nat_is_pow a (b - 1);
LE.lemma_pow_unfold k a b;
() end
let lemma_pow_zero b =
lemma_pow_unfold 0 b
let lemma_pow_one b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_one k b;
lemma_pow_nat_is_pow 1 b
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_add k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow x m;
lemma_pow_nat_is_pow x (n + m)
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul k x n m;
lemma_pow_nat_is_pow x n;
lemma_pow_nat_is_pow (pow x n) m;
lemma_pow_nat_is_pow x (n * m)
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in
LE.lemma_pow_double k a b;
lemma_pow_nat_is_pow (a * a) b;
lemma_pow_nat_is_pow a (b + b)
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in
LE.lemma_pow_mul_base k a b n;
lemma_pow_nat_is_pow a n;
lemma_pow_nat_is_pow b n;
lemma_pow_nat_is_pow (a * b) n
let rec lemma_pow_mod_base a b n =
if b = 0 then begin
lemma_pow0 a;
lemma_pow0 (a % n) end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_mod_base a (b - 1) n }
a * (pow (a % n) (b - 1) % n) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n }
a * pow (a % n) (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n }
a % n * pow (a % n) (b - 1) % n;
(==) { lemma_pow_unfold (a % n) b }
pow (a % n) b % n;
};
assert (pow a b % n == pow (a % n) b % n)
end
let lemma_mul_mod_one #m a = ()
let lemma_mul_mod_assoc #m a b c =
calc (==) {
(a * b % m) * c % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m }
(a * b) * c % m;
(==) { Math.Lemmas.paren_mul_right a b c }
a * (b * c) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m }
a * (b * c % m) % m;
}
let lemma_mul_mod_comm #m a b = ()
let pow_mod #m a b = pow_mod_ #m a b
let pow_mod_def #m a b = ()
#push-options "--fuel 2"
val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1)
let lemma_pow_mod0 #n a = ()
val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma
(pow_mod #n a b == pow_mod (mul_mod a a) (b / 2))
let lemma_pow_mod_unfold0 n a b = ()
val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma
(pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2)))
let lemma_pow_mod_unfold1 n a b = ()
#pop-options
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma
(ensures (pow_mod #n a b == pow a b % n))
(decreases b)
let rec lemma_pow_mod_ n a b =
if b = 0 then begin
lemma_pow0 a;
lemma_pow_mod0 a end
else begin
if b % 2 = 0 then begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold0 n a b }
pow_mod #n (mul_mod #n a a) (b / 2);
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
pow (mul_mod #n a a) (b / 2) % n;
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
pow (a * a) (b / 2) % n;
(==) { lemma_pow_double a (b / 2) }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
else begin
calc (==) {
pow_mod #n a b;
(==) { lemma_pow_mod_unfold1 n a b }
mul_mod a (pow_mod (mul_mod #n a a) (b / 2));
(==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) }
mul_mod a (pow (mul_mod #n a a) (b / 2) % n);
(==) { lemma_pow_mod_base (a * a) (b / 2) n }
mul_mod a (pow (a * a) (b / 2) % n);
(==) { lemma_pow_double a (b / 2) }
mul_mod a (pow a (b / 2 * 2) % n);
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n }
a * pow a (b / 2 * 2) % n;
(==) { lemma_pow1 a }
pow a 1 * pow a (b / 2 * 2) % n;
(==) { lemma_pow_add a 1 (b / 2 * 2) }
pow a (b / 2 * 2 + 1) % n;
(==) { Math.Lemmas.euclidean_division_definition b 2 }
pow a b % n;
};
assert (pow_mod #n a b == pow a b % n) end
end
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in
if b = 0 then begin
lemma_pow0 a;
LE.lemma_pow0 k a end
else begin
calc (==) {
pow a b % n;
(==) { lemma_pow_unfold a b }
a * pow a (b - 1) % n;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n }
a * (pow a (b - 1) % n) % n;
(==) { lemma_pow_nat_mod_is_pow #n a (b - 1) }
a * LE.pow k a (b - 1) % n;
(==) { }
k.LE.mul a (LE.pow k a (b - 1));
(==) { LE.lemma_pow_unfold k a b }
LE.pow k a b;
}; () end
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
let lemma_add_mod_assoc #m a b c =
calc (==) {
add_mod (add_mod a b) c;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m }
((a + b) + c) % m;
(==) { }
(a + (b + c)) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m }
add_mod a (add_mod b c);
}
let lemma_add_mod_comm #m a b = ()
let lemma_mod_distributivity_add_right #m a b c =
calc (==) {
mul_mod a (add_mod b c);
(==) { }
a * ((b + c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m }
a * (b + c) % m;
(==) { Math.Lemmas.distributivity_add_right a b c }
(a * b + a * c) % m;
(==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m }
add_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
let lemma_mod_distributivity_sub_right #m a b c =
calc (==) {
mul_mod a (sub_mod b c);
(==) { }
a * ((b - c) % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m }
a * (b - c) % m;
(==) { Math.Lemmas.distributivity_sub_right a b c }
(a * b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m }
(mul_mod a b - a * c) % m;
(==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m }
sub_mod (mul_mod a b) (mul_mod a c);
}
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in
let p2 = pow b (m - 2) in
calc (==) {
mul_mod (inv_mod a) (inv_mod b);
(==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) }
p1 % m * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m }
p1 * (p2 % m) % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m }
p1 * p2 % m;
(==) { lemma_pow_mul_base a b (m - 2) }
pow (a * b) (m - 2) % m;
(==) { lemma_pow_mod_base (a * b) (m - 2) m }
pow (mul_mod a b) (m - 2) % m;
(==) { lemma_pow_mod #m (mul_mod a b) (m - 2) }
inv_mod (mul_mod a b);
}
#push-options "--fuel 1"
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n =
if n = 0 then ()
else pow_eq a (n - 1)
#pop-options
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m;
assert (a == a % m);
assert (a <> 0 /\ a % m <> 0);
calc (==) {
pow_mod #m a (m - 2) * a % m;
(==) { lemma_pow_mod #m a (m - 2) }
pow a (m - 2) % m * a % m;
(==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m }
pow a (m - 2) * a % m;
(==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 }
pow a (m - 1) % m;
(==) { pow_eq a (m - 1) }
Fermat.pow a (m - 1) % m;
(==) { Fermat.fermat_alt m a }
1;
}
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2);
lemma_pow_one (m - 2);
Math.Lemmas.small_mod 1 m
let lemma_div_mod_prime_cancel #m a b c =
calc (==) {
mul_mod (mul_mod a c) (inv_mod (mul_mod c b));
(==) { lemma_inv_mod_both c b }
mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b));
(==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) }
mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b);
(==) { lemma_mul_mod_assoc a c (inv_mod c) }
mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b);
(==) { lemma_div_mod_prime c }
mul_mod (mul_mod a 1) (inv_mod b);
(==) { Math.Lemmas.small_mod a m }
mul_mod a (inv_mod b);
}
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc (==) {
mul_mod (div_mod a c) (div_mod b d);
(==) { }
mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d));
(==) {
lemma_mul_mod_comm #m b (inv_mod d);
lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b }
mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b;
(==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) }
mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b;
(==) { lemma_inv_mod_both c d }
mul_mod (mul_mod a (inv_mod (mul_mod c d))) b;
(==) {
lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b;
lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b;
lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) }
mul_mod (mul_mod a b) (inv_mod (mul_mod c d));
}
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then begin
assert (mul_mod (div_mod a b) b = mul_mod c b);
calc (==) {
mul_mod (div_mod a b) b;
(==) { lemma_div_mod_prime_one b }
mul_mod (div_mod a b) (div_mod b 1);
(==) { lemma_div_mod_prime_to_one_denominator a b b 1 }
div_mod (mul_mod a b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel a 1 b }
div_mod a 1;
(==) { lemma_div_mod_prime_one a }
a;
} end
else ()
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m ->
Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then begin
assert (div_mod a b == div_mod (mul_mod c b) b);
calc (==) {
div_mod (mul_mod c b) b;
(==) { Math.Lemmas.small_mod b m }
div_mod (mul_mod c b) (mul_mod b 1);
(==) { lemma_div_mod_prime_cancel c 1 b }
div_mod c 1;
(==) { lemma_div_mod_prime_one c }
c;
} end
else ()
let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c;
lemma_div_mod_eq_mul_mod2 a b c
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma
(requires x % n == 0 \/ y % n == 0)
(ensures x * y % n == 0)
let lemma_mul_mod_zero2 n x y =
if x % n = 0 then
Math.Lemmas.lemma_mod_mul_distr_l x y n
else
Math.Lemmas.lemma_mod_mul_distr_r x y n
let lemma_mul_mod_prime_zero #m a b =
Classical.move_requires_3 Euclid.euclid_prime m a b;
Classical.move_requires_3 lemma_mul_mod_zero2 m a b
val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma
(requires pow a b % m = 0)
(ensures a = 0) | false | false | Lib.NatMod.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma
(requires pow a b % m = 0)
(ensures a = 0) | [
"recursion"
] | Lib.NatMod.lemma_pow_mod_prime_zero_ | {
"file_name": "lib/Lib.NatMod.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.NatMod.nat_mod m -> b: Prims.pos
-> FStar.Pervasives.Lemma (requires Lib.NatMod.pow a b % m = 0) (ensures a = 0) | {
"end_col": 68,
"end_line": 431,
"start_col": 2,
"start_line": 423
} |
Prims.Tot | [
{
"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
}
] | false | let n = 8 | let n = | false | null | false | 8 | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) | false | true | FStar.UInt8.fsti | {
"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"
} | null | val n : Prims.int | [] | FStar.UInt8.n | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | Prims.int | {
"end_col": 16,
"end_line": 20,
"start_col": 15,
"start_line": 20
} |
|
Prims.Tot | val lt (a b: t) : Tot bool | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) | val lt (a b: t) : Tot bool
let lt (a b: t) : Tot bool = | false | null | false | lt #n (v a) (v b) | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.t",
"FStar.UInt.lt",
"FStar.UInt8.n",
"FStar.UInt8.v",
"Prims.bool"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) | false | true | FStar.UInt8.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lt (a b: t) : Tot bool | [] | FStar.UInt8.lt | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 49,
"end_line": 232,
"start_col": 32,
"start_line": 232
} |
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Plus_Question_Hat = add_underspec | let op_Plus_Question_Hat = | false | null | false | add_underspec | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.add_underspec"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *) | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Plus_Question_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Plus_Question_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 47,
"end_line": 316,
"start_col": 34,
"start_line": 316
} |
|
Prims.Tot | val gt (a b: t) : Tot bool | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) | val gt (a b: t) : Tot bool
let gt (a b: t) : Tot bool = | false | null | false | gt #n (v a) (v b) | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.t",
"FStar.UInt.gt",
"FStar.UInt8.n",
"FStar.UInt8.v",
"Prims.bool"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) | false | true | FStar.UInt8.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gt (a b: t) : Tot bool | [] | FStar.UInt8.gt | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 49,
"end_line": 226,
"start_col": 32,
"start_line": 226
} |
Prims.Tot | val gte (a b: t) : Tot bool | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) | val gte (a b: t) : Tot bool
let gte (a b: t) : Tot bool = | false | null | false | gte #n (v a) (v b) | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.t",
"FStar.UInt.gte",
"FStar.UInt8.n",
"FStar.UInt8.v",
"Prims.bool"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) | false | true | FStar.UInt8.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gte (a b: t) : Tot bool | [] | FStar.UInt8.gte | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 51,
"end_line": 229,
"start_col": 33,
"start_line": 229
} |
Prims.Tot | val eq (a b: t) : Tot bool | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) | val eq (a b: t) : Tot bool
let eq (a b: t) : Tot bool = | false | null | false | eq #n (v a) (v b) | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.t",
"FStar.UInt.eq",
"FStar.UInt8.n",
"FStar.UInt8.v",
"Prims.bool"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality | false | true | FStar.UInt8.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eq (a b: t) : Tot bool | [] | FStar.UInt8.eq | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 49,
"end_line": 223,
"start_col": 32,
"start_line": 223
} |
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Subtraction_Question_Hat = sub_underspec | let op_Subtraction_Question_Hat = | false | null | false | sub_underspec | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.sub_underspec"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Subtraction_Question_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Subtraction_Question_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 54,
"end_line": 319,
"start_col": 41,
"start_line": 319
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Plus_Hat = add | let op_Plus_Hat = | false | null | false | add | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.add"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Plus_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Plus_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 28,
"end_line": 315,
"start_col": 25,
"start_line": 315
} |
|
Prims.Tot | val lte (a b: t) : Tot bool | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) | val lte (a b: t) : Tot bool
let lte (a b: t) : Tot bool = | false | null | false | lte #n (v a) (v b) | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.t",
"FStar.UInt.lte",
"FStar.UInt8.n",
"FStar.UInt8.v",
"Prims.bool"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) | false | true | FStar.UInt8.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lte (a b: t) : Tot bool | [] | FStar.UInt8.lte | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 51,
"end_line": 235,
"start_col": 33,
"start_line": 235
} |
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Percent_Hat = rem | let op_Percent_Hat = | false | null | false | rem | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.rem"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec
unfold let op_Star_Percent_Hat = mul_mod | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Percent_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Percent_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t | {
"end_col": 31,
"end_line": 325,
"start_col": 28,
"start_line": 325
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Greater_Hat = gt | let op_Greater_Hat = | false | null | false | gt | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.gt"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec
unfold let op_Star_Percent_Hat = mul_mod
unfold let op_Slash_Hat = div
unfold let op_Percent_Hat = rem
unfold let op_Hat_Hat = logxor
unfold let op_Amp_Hat = logand
unfold let op_Bar_Hat = logor
unfold let op_Less_Less_Hat = shift_left
unfold let op_Greater_Greater_Hat = shift_right | false | true | FStar.UInt8.fsti | {
"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"
} | null | val op_Greater_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | [] | FStar.UInt8.op_Greater_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 30,
"end_line": 332,
"start_col": 28,
"start_line": 332
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Amp_Hat = logand | let op_Amp_Hat = | false | null | false | logand | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.logand"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec
unfold let op_Star_Percent_Hat = mul_mod
unfold let op_Slash_Hat = div
unfold let op_Percent_Hat = rem | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Amp_Hat : x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Amp_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 30,
"end_line": 327,
"start_col": 24,
"start_line": 327
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Plus_Percent_Hat = add_mod | let op_Plus_Percent_Hat = | false | null | false | add_mod | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.add_mod"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Plus_Percent_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Plus_Percent_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 40,
"end_line": 317,
"start_col": 33,
"start_line": 317
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Subtraction_Percent_Hat = sub_mod | let op_Subtraction_Percent_Hat = | false | null | false | sub_mod | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.sub_mod"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Subtraction_Percent_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Subtraction_Percent_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 47,
"end_line": 320,
"start_col": 40,
"start_line": 320
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Equals_Hat = eq | let op_Equals_Hat = | false | null | false | eq | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.eq"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec
unfold let op_Star_Percent_Hat = mul_mod
unfold let op_Slash_Hat = div
unfold let op_Percent_Hat = rem
unfold let op_Hat_Hat = logxor
unfold let op_Amp_Hat = logand
unfold let op_Bar_Hat = logor
unfold let op_Less_Less_Hat = shift_left | false | true | FStar.UInt8.fsti | {
"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"
} | null | val op_Equals_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | [] | FStar.UInt8.op_Equals_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 29,
"end_line": 331,
"start_col": 27,
"start_line": 331
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Slash_Hat = div | let op_Slash_Hat = | false | null | false | div | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.div"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Slash_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Slash_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t | {
"end_col": 29,
"end_line": 324,
"start_col": 26,
"start_line": 324
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Bar_Hat = logor | let op_Bar_Hat = | false | null | false | logor | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.logor"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec
unfold let op_Star_Percent_Hat = mul_mod
unfold let op_Slash_Hat = div
unfold let op_Percent_Hat = rem
unfold let op_Hat_Hat = logxor | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Bar_Hat : x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Bar_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 29,
"end_line": 328,
"start_col": 24,
"start_line": 328
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Subtraction_Hat = sub | let op_Subtraction_Hat = | false | null | false | sub | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.sub"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Subtraction_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Subtraction_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 35,
"end_line": 318,
"start_col": 32,
"start_line": 318
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Star_Question_Hat = mul_underspec | let op_Star_Question_Hat = | false | null | false | mul_underspec | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.mul_underspec"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Star_Question_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Star_Question_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 47,
"end_line": 322,
"start_col": 34,
"start_line": 322
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Less_Equals_Hat = lte | let op_Less_Equals_Hat = | false | null | false | lte | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.lte"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec
unfold let op_Star_Percent_Hat = mul_mod
unfold let op_Slash_Hat = div
unfold let op_Percent_Hat = rem
unfold let op_Hat_Hat = logxor
unfold let op_Amp_Hat = logand
unfold let op_Bar_Hat = logor
unfold let op_Less_Less_Hat = shift_left
unfold let op_Greater_Greater_Hat = shift_right
unfold let op_Equals_Hat = eq
unfold let op_Greater_Hat = gt
unfold let op_Greater_Equals_Hat = gte | false | true | FStar.UInt8.fsti | {
"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"
} | null | val op_Less_Equals_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | [] | FStar.UInt8.op_Less_Equals_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 35,
"end_line": 335,
"start_col": 32,
"start_line": 335
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Star_Percent_Hat = mul_mod | let op_Star_Percent_Hat = | false | null | false | mul_mod | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.mul_mod"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Star_Percent_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Star_Percent_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 40,
"end_line": 323,
"start_col": 33,
"start_line": 323
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Hat_Hat = logxor | let op_Hat_Hat = | false | null | false | logxor | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.logxor"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec
unfold let op_Star_Percent_Hat = mul_mod
unfold let op_Slash_Hat = div | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Hat_Hat : x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Hat_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 30,
"end_line": 326,
"start_col": 24,
"start_line": 326
} |
|
Prims.Pure | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Star_Hat = mul | let op_Star_Hat = | false | null | false | mul | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [] | [
"FStar.UInt8.mul"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec | false | false | FStar.UInt8.fsti | {
"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"
} | null | val op_Star_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | [] | FStar.UInt8.op_Star_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | {
"end_col": 28,
"end_line": 321,
"start_col": 25,
"start_line": 321
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"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
}
] | false | let op_Less_Hat = lt | let op_Less_Hat = | false | null | false | lt | {
"checked_file": "FStar.UInt8.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.UInt8.fsti"
} | [
"total"
] | [
"FStar.UInt8.lt"
] | [] | (*
Copyright 2008-2019 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.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
unfold let n = 8
/// For FStar.UIntN.fstp: anything that you fix/update here should be
/// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of
/// this module.
///
/// Except, as compared to [FStar.IntN.fstp], here:
/// - every occurrence of [int_t] has been replaced with [uint_t]
/// - every occurrence of [@%] has been replaced with [%].
/// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers
/// This module provides an abstract type for machine integers of a
/// given signedness and width. The interface is designed to be safe
/// with respect to arithmetic underflow and overflow.
/// Note, we have attempted several times to re-design this module to
/// make it more amenable to normalization and to impose less overhead
/// on the SMT solver when reasoning about machine integer
/// arithmetic. The following github issue reports on the current
/// status of that work.
///
/// https://github.com/FStarLang/FStar/issues/1757
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
(** Abstract type of machine integers, with an underlying
representation using a bounded mathematical integer *)
new val t : eqtype
(** A coercion that projects a bounded mathematical integer from a
machine integer *)
val v (x:t) : Tot (uint_t n)
(** A coercion that injects a bounded mathematical integers into a
machine integer *)
val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x))
(** Injection/projection inverse *)
val uv_inv (x : t) : Lemma
(ensures (uint_to_t (v x) == x))
[SMTPat (v x)]
(** Projection/injection inverse *)
val vu_inv (x : uint_t n) : Lemma
(ensures (v (uint_to_t x) == x))
[SMTPat (uint_to_t x)]
(** An alternate form of the injectivity of the [v] projection *)
val v_inj (x1 x2: t): Lemma
(requires (v x1 == v x2))
(ensures (x1 == x2))
(** Constants 0 and 1 *)
val zero : x:t{v x = 0}
val one : x:t{v x = 1}
(**** Addition primitives *)
(** Bounds-respecting addition
The precondition enforces that the sum does not overflow,
expressing the bound as an addition on mathematical integers *)
val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c))
(** Underspecified, possibly overflowing addition:
The postcondition only enures that the result is the sum of the
arguments in case there is no overflow *)
val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c))
(** Addition modulo [2^n]
Machine integers can always be added, but the postcondition is now
in terms of addition modulo [2^n] on mathematical integers *)
val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c))
(**** Subtraction primitives *)
(** Bounds-respecting subtraction
The precondition enforces that the difference does not underflow,
expressing the bound as a difference on mathematical integers *)
val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c))
(** Underspecified, possibly overflowing subtraction:
The postcondition only enures that the result is the difference of
the arguments in case there is no underflow *)
val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c))
(** Subtraction modulo [2^n]
Machine integers can always be subtractd, but the postcondition is
now in terms of subtraction modulo [2^n] on mathematical integers *)
val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c))
(**** Multiplication primitives *)
(** Bounds-respecting multiplication
The precondition enforces that the product does not overflow,
expressing the bound as a product on mathematical integers *)
val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c))
(** Underspecified, possibly overflowing product
The postcondition only enures that the result is the product of
the arguments in case there is no overflow *)
val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c))
(** Multiplication modulo [2^n]
Machine integers can always be multiplied, but the postcondition
is now in terms of product modulo [2^n] on mathematical integers *)
val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c))
(**** Division primitives *)
(** Euclidean division of [a] and [b], with [b] non-zero *)
val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c))
(**** Modulo primitives *)
(** Euclidean remainder
The result is the modulus of [a] with respect to a non-zero [b] *)
val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c))
(**** Bitwise operators *)
/// Also see FStar.BV
(** Bitwise logical conjunction *)
val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z))
(** Bitwise logical exclusive-or *)
val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z))
(** Bitwise logical disjunction *)
val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z))
(** Bitwise logical negation *)
val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z))
(**** Shift operators *)
(** Shift right with zero fill, shifting at most the integer width *)
val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c))
(** Shift left with zero fill, shifting at most the integer width *)
val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c))
(**** Comparison operators *)
(** Equality
Note, it is safe to also use the polymorphic decidable equality
operator [=] *)
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
(** Greater than *)
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
(** Greater than or equal *)
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
(** Less than *)
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
(** Less than or equal *)
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
(** Unary negation *)
inline_for_extraction
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
(** The maximum value for this type *)
inline_for_extraction
let n_minus_one = UInt32.uint_to_t (n - 1)
#set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1"
(** A constant-time way to compute the equality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b
Note, the branching on [a=b] is just for proof-purposes.
*)
[@ CNoInline ]
let eq_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\
(v a <> v b ==> v c = 0)))
= let x = logxor a b in
let minus_x = minus x in
let x_or_minus_x = logor x minus_x in
let xnx = shift_right x_or_minus_x n_minus_one in
let c = sub_mod xnx (uint_to_t 1) in
if a = b then
begin
logxor_self (v a);
lognot_lemma_1 #n;
logor_lemma_1 (v x);
assert (v x = 0 /\ v minus_x = 0 /\
v x_or_minus_x = 0 /\ v xnx = 0);
assert (v c = ones n)
end
else
begin
logxor_neq_nonzero (v a) (v b);
lemma_msb_pow2 #n (v (lognot x));
lemma_msb_pow2 #n (v minus_x);
lemma_minus_zero #n (v x);
assert (v c = FStar.UInt.zero n)
end;
c
private
val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b))))
(** A constant-time way to compute the [>=] inequality of
two machine integers.
With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a
*)
[@ CNoInline ]
let gte_mask (a:t) (b:t)
: Pure t
(requires True)
(ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\
(v a < v b ==> v c = 0)))
= let x = a in
let y = b in
let x_xor_y = logxor x y in
let x_sub_y = sub_mod x y in
let x_sub_y_xor_y = logxor x_sub_y y in
let q = logor x_xor_y x_sub_y_xor_y in
let x_xor_q = logxor x q in
let x_xor_q_ = shift_right x_xor_q n_minus_one in
let c = sub_mod x_xor_q_ (uint_to_t 1) in
lemma_sub_msbs x y;
lemma_msb_gte (v x) (v y);
lemma_msb_gte (v y) (v x);
c
#reset-options
(*** Infix notations *)
unfold let op_Plus_Hat = add
unfold let op_Plus_Question_Hat = add_underspec
unfold let op_Plus_Percent_Hat = add_mod
unfold let op_Subtraction_Hat = sub
unfold let op_Subtraction_Question_Hat = sub_underspec
unfold let op_Subtraction_Percent_Hat = sub_mod
unfold let op_Star_Hat = mul
unfold let op_Star_Question_Hat = mul_underspec
unfold let op_Star_Percent_Hat = mul_mod
unfold let op_Slash_Hat = div
unfold let op_Percent_Hat = rem
unfold let op_Hat_Hat = logxor
unfold let op_Amp_Hat = logand
unfold let op_Bar_Hat = logor
unfold let op_Less_Less_Hat = shift_left
unfold let op_Greater_Greater_Hat = shift_right
unfold let op_Equals_Hat = eq
unfold let op_Greater_Hat = gt | false | true | FStar.UInt8.fsti | {
"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"
} | null | val op_Less_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | [] | FStar.UInt8.op_Less_Hat | {
"file_name": "ulib/FStar.UInt8.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool | {
"end_col": 27,
"end_line": 334,
"start_col": 25,
"start_line": 334
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.