file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Seq.Base.fst | FStar.Seq.Base.init_aux_ghost' | val init_aux_ghost' (#a: Type) (len: nat) (k: nat{k < len}) (contents: (i: nat{i < len} -> GTot a))
: GTot (seq a) (decreases (len - k)) | val init_aux_ghost' (#a: Type) (len: nat) (k: nat{k < len}) (contents: (i: nat{i < len} -> GTot a))
: GTot (seq a) (decreases (len - k)) | let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 64,
"end_line": 60,
"start_col": 8,
"start_line": 55
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Prims.nat -> k: Prims.nat{k < len} -> contents: (i: Prims.nat{i < len} -> Prims.GTot a)
-> Prims.GTot (FStar.Seq.Base.seq a) | Prims.GTot | [
"sometrivial",
""
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"FStar.Seq.Base.MkSeq",
"Prims.Cons",
"Prims.Nil",
"Prims.bool",
"FStar.Seq.Base._cons",
"FStar.Seq.Base.init_aux_ghost'",
"FStar.Seq.Base.seq"
] | [
"recursion"
] | false | false | false | false | false | let rec init_aux_ghost'
(#a: Type)
(len: nat)
(k: nat{k < len})
(contents: (i: nat{i < len} -> GTot a))
: GTot (seq a) (decreases (len - k)) =
| if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k + 1) contents) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.upd' | val upd' (#a: Type) (s: seq a) (n: nat{n < length s}) (v: a) : Tot (seq a) (decreases (length s)) | val upd' (#a: Type) (s: seq a) (n: nat{n < length s}) (v: a) : Tot (seq a) (decreases (length s)) | let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 73,
"start_col": 8,
"start_line": 70
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> n: Prims.nat{n < FStar.Seq.Base.length s} -> v: a
-> Prims.Tot (FStar.Seq.Base.seq a) | Prims.Tot | [
"total",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base._cons",
"FStar.Seq.Base.tl",
"Prims.bool",
"FStar.Seq.Base.hd",
"FStar.Seq.Base.upd'",
"Prims.op_Subtraction"
] | [
"recursion"
] | false | false | false | false | false | let rec upd' (#a: Type) (s: seq a) (n: nat{n < length s}) (v: a)
: Tot (seq a) (decreases (length s)) =
| if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.empty | val empty (#a:Type) : Tot (s:(seq a){length s=0}) | val empty (#a:Type) : Tot (s:(seq a){length s=0}) | let empty #_ = MkSeq [] | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 66,
"start_col": 0,
"start_line": 66
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s = 0} | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.MkSeq",
"Prims.Nil",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length"
] | [] | false | false | false | false | false | let empty #_ =
| MkSeq [] | false |
FStar.Seq.Base.fst | FStar.Seq.Base.init_ghost | val init_ghost: #a:Type -> len:nat -> contents: (i:nat { i < len } -> GTot a) -> GTot (seq a) | val init_ghost: #a:Type -> len:nat -> contents: (i:nat { i < len } -> GTot a) -> GTot (seq a) | let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 92,
"end_line": 64,
"start_col": 0,
"start_line": 64
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Prims.nat -> contents: (i: Prims.nat{i < len} -> Prims.GTot a)
-> Prims.GTot (FStar.Seq.Base.seq a) | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.MkSeq",
"Prims.Nil",
"Prims.bool",
"FStar.Seq.Base.init_aux_ghost",
"FStar.Seq.Base.seq"
] | [] | false | false | false | false | false | let init_ghost #_ len contents =
| if len = 0 then MkSeq [] else init_aux_ghost len 0 contents | false |
Pulse.C.Types.Union.fsti | Pulse.C.Types.Union.union_field1 | val union_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field)) | val union_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field)) | let union_field1
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
= union_field0 t' r field td' | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Union.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 29,
"end_line": 377,
"start_col": 0,
"start_line": 362
} | module Pulse.C.Types.Union
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
[@@noextract_to "krml"] // primitive
val define_union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_union (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0
= define_union0 tn #tf n fields
// To be extracted as: union t
[@@noextract_to "krml"] // primitive
val union_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let union_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0
= union_t0 tn #tf n fields
val union_set_field (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) (f: field_t fields) (v: fields.fd_type f) : GTot (union_t0 tn n fields)
val union_get_case
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(u: union_t0 tn n fields)
: GTot (option (field_t fields))
val union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(u: union_t0 tn n fields)
(field: field_t fields)
: Ghost (fields.fd_type field)
(requires (union_get_case u == Some field))
(ensures (fun _ -> True))
val union_get_field_same
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (~ (v == unknown (fields.fd_typedef field))))
(ensures (
let u = union_set_field tn n fields field v in
union_get_case u == Some field /\
union_get_field u field == v
))
[SMTPatOr [
[SMTPat (union_get_case (union_set_field tn n fields field v))];
[SMTPat (union_get_field (union_set_field tn n fields field v) field)];
]]
val union_set_field_same
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
union_set_field tn n fields field (union_get_field s field) == s
))
[SMTPat (union_set_field tn n fields (union_get_field s field))]
[@@noextract_to "krml"] // proof-only
val union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields))
inline_for_extraction
[@@noextract_to "krml"; norm_field_attr] // proof-only
let union (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields))
= union0 tn #tf n fields
val union_get_case_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
: Lemma
(union_get_case (unknown (union0 tn n fields)) == None)
[SMTPat (unknown (union0 tn n fields))]
val union_set_field_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
: Lemma
(union_set_field tn n fields field (unknown (fields.fd_typedef field)) == unknown (union0 tn n fields))
[SMTPat (union_set_field tn n fields field (unknown (fields.fd_typedef field)))]
val union_get_case_uninitialized
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
: Lemma
(union_get_case (uninitialized (union0 tn n fields)) == None)
[SMTPat (uninitialized (union0 tn n fields))]
val mk_fraction_union_get_case
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(p: perm)
: Lemma
(requires (fractionable (union0 tn n fields) s))
(ensures (
union_get_case (mk_fraction (union0 tn n fields) s p) == union_get_case s
))
[SMTPat (union_get_case (mk_fraction (union0 tn n fields) s p))]
val fractionable_union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
fractionable (union0 tn n fields) s <==> fractionable (fields.fd_typedef field) (union_get_field s field)
))
[SMTPat (fractionable (union0 tn n fields) s); SMTPat (union_get_field s field)]
val mk_fraction_union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(p: perm)
(field: field_t fields)
: Lemma
(requires (fractionable (union0 tn n fields) s /\ union_get_case s == Some field))
(ensures (union_get_field (mk_fraction (union0 tn n fields) s p) field == mk_fraction (fields.fd_typedef field) (union_get_field s field) p))
[SMTPat (union_get_field (mk_fraction (union0 tn n fields) s p) field)]
val mk_fraction_union_set_field
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
(p: perm)
: Lemma
(requires (fractionable (fields.fd_typedef field) v))
(ensures (
fractionable (union0 tn n fields) (union_set_field tn n fields field v) /\
mk_fraction (union0 tn n fields) (union_set_field tn n fields field v) p == union_set_field tn n fields field (mk_fraction (fields.fd_typedef field) v p)
))
val full_union
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
full (union0 tn n fields) s <==> full (fields.fd_typedef field) (union_get_field s field)
))
[SMTPat (full (union0 tn n fields) s); SMTPat (union_get_field s field)]
let full_union_set_field_intro
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (full (fields.fd_typedef field) v))
(ensures (
full (union0 tn n fields) (union_set_field tn n fields field v)
))
= full_union (union_set_field tn n fields field v) field
let full_union_set_field_elim
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (
full (union0 tn n fields) (union_set_field tn n fields field v)
))
(ensures (
full (fields.fd_typedef field) v
))
= full_union (union_set_field tn n fields field v) field
let full_union_set_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires True)
(ensures (
full (union0 tn n fields) (union_set_field tn n fields field v) <==> full (fields.fd_typedef field) v
))
[SMTPat (full (union0 tn n fields) (union_set_field tn n fields field v))]
= Classical.move_requires (full_union_set_field_intro #tn #tf #n #fields field) v;
Classical.move_requires (full_union_set_field_elim #tn #tf #n #fields field) v
val has_union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: Tot vprop
val has_union_field_prop
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r field r')
(fun _ -> has_union_field r field r' ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
val has_union_field_dup
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r field r')
(fun _ -> has_union_field r field r' ** has_union_field r field r')
val has_union_field_inj
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t1: Type0)
(#td1: typedef t1)
(r1: ref td1)
(#t2: Type0)
(#td2: typedef t2)
(r2: ref td2)
: stt_ghost (squash (t1 == t2 /\ td1 == td2))
(has_union_field r field r1 ** has_union_field r field r2)
(fun _ -> has_union_field r field r1 ** has_union_field r field r2 ** ref_equiv r1 (coerce_eq () r2))
val has_union_field_equiv_from
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r1 r2: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r1 field r' ** ref_equiv r1 r2)
(fun _ -> has_union_field r2 field r' ** ref_equiv r1 r2)
val has_union_field_equiv_to
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r1 r2: ref td')
: stt_ghost unit
(has_union_field r field r1 ** ref_equiv r1 r2)
(fun _ -> has_union_field r field r2 ** ref_equiv r1 r2)
val ghost_union_field_focus
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost (squash (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
(has_union_field r field r' ** pts_to r v)
(fun _ -> has_union_field r field r' ** pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field))))
val ghost_union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
: stt_ghost (Ghost.erased (ref (fields.fd_typedef field)))
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
[@@noextract_to "krml"] // primitive
val union_field0
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t' {
t' == fields.fd_type field /\
td' == fields.fd_typedef field
})
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field)))) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Union.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t': Type0 ->
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Union.union0 tn n fields) ->
field:
Pulse.C.Types.Fields.field_t fields
{ Pulse.C.Types.Union.union_get_case (FStar.Ghost.reveal v) ==
FStar.Pervasives.Native.Some field } ->
td': Pulse.C.Types.Base.typedef t' ->
sq_t': Prims.squash (t' == Mkfield_description_t?.fd_type fields field) ->
sq_td': Prims.squash (td' == Mkfield_description_t?.fd_typedef fields field)
-> Pulse.Lib.Core.stt (Pulse.C.Types.Base.ref td')
(Pulse.C.Types.Base.pts_to r v)
(fun r' ->
Pulse.C.Types.Union.has_union_field r field r' **
Pulse.C.Types.Base.pts_to r'
(FStar.Ghost.hide (Pulse.C.Types.Union.union_get_field (FStar.Ghost.reveal v) field))) | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Pulse.C.Types.Fields.field_description_t",
"FStar.Ghost.erased",
"Pulse.C.Types.Union.union_t0",
"Pulse.C.Types.Base.ref",
"Pulse.C.Types.Union.union0",
"Pulse.C.Types.Fields.field_t",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Pulse.C.Types.Union.union_get_case",
"FStar.Ghost.reveal",
"FStar.Pervasives.Native.Some",
"Pulse.C.Types.Base.typedef",
"Prims.squash",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef",
"Pulse.C.Types.Union.union_field0",
"Pulse.Lib.Core.stt",
"Pulse.C.Types.Base.pts_to",
"Pulse.Lib.Core.op_Star_Star",
"Pulse.C.Types.Union.has_union_field",
"FStar.Ghost.hide",
"Pulse.C.Types.Union.union_get_field",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | false | let union_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field)) =
| union_field0 t' r field td' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_init_aux_len | val lemma_init_aux_len (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
[SMTPat (length (init_aux n k contents))] | val lemma_init_aux_len (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
[SMTPat (length (init_aux n k contents))] | let lemma_init_aux_len = lemma_init_aux_len' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 103,
"start_col": 0,
"start_line": 103
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> k: Prims.nat{k < n} -> contents: (i: Prims.nat{i < n} -> a)
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.length (FStar.Seq.Base.init_aux n k contents) = n - k)
[SMTPat (FStar.Seq.Base.length (FStar.Seq.Base.init_aux n k contents))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.lemma_init_aux_len'"
] | [] | true | false | true | false | false | let lemma_init_aux_len =
| lemma_init_aux_len' | false |
Pulse.C.Types.Union.fsti | Pulse.C.Types.Union.union_switch_field | val union_switch_field:
#tn: Type0 ->
#tf: Type0 ->
#n: string ->
#fields: field_description_t tf ->
#v: Ghost.erased (union_t0 tn n fields) ->
r: ref (union0 tn n fields) ->
field: field_t fields ->
#t': Type0 ->
#td': typedef t' ->
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field)) ->
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field)) ->
Prims.unit
-> stt (ref td')
(pts_to r v ** pure (full (union0 tn n fields) v))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td')) | val union_switch_field:
#tn: Type0 ->
#tf: Type0 ->
#n: string ->
#fields: field_description_t tf ->
#v: Ghost.erased (union_t0 tn n fields) ->
r: ref (union0 tn n fields) ->
field: field_t fields ->
#t': Type0 ->
#td': typedef t' ->
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field)) ->
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field)) ->
Prims.unit
-> stt (ref td')
(pts_to r v ** pure (full (union0 tn n fields) v))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td')) | let union_switch_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(# [ norm_fields () ] sq_t': squash (t' == fields.fd_type field))
(# [ norm_fields () ] sq_td': squash (td' == fields.fd_typedef field))
()
: stt (ref td') // need to write the pcm carrier value, so this cannot be Ghost or Atomic
(pts_to r v ** pure (
full (union0 tn n fields) v
))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td'))
= union_switch_field0
t'
r
field
td' | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Union.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 515,
"start_col": 0,
"start_line": 493
} | module Pulse.C.Types.Union
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
[@@noextract_to "krml"] // primitive
val define_union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_union (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0
= define_union0 tn #tf n fields
// To be extracted as: union t
[@@noextract_to "krml"] // primitive
val union_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let union_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0
= union_t0 tn #tf n fields
val union_set_field (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) (f: field_t fields) (v: fields.fd_type f) : GTot (union_t0 tn n fields)
val union_get_case
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(u: union_t0 tn n fields)
: GTot (option (field_t fields))
val union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(u: union_t0 tn n fields)
(field: field_t fields)
: Ghost (fields.fd_type field)
(requires (union_get_case u == Some field))
(ensures (fun _ -> True))
val union_get_field_same
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (~ (v == unknown (fields.fd_typedef field))))
(ensures (
let u = union_set_field tn n fields field v in
union_get_case u == Some field /\
union_get_field u field == v
))
[SMTPatOr [
[SMTPat (union_get_case (union_set_field tn n fields field v))];
[SMTPat (union_get_field (union_set_field tn n fields field v) field)];
]]
val union_set_field_same
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
union_set_field tn n fields field (union_get_field s field) == s
))
[SMTPat (union_set_field tn n fields (union_get_field s field))]
[@@noextract_to "krml"] // proof-only
val union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields))
inline_for_extraction
[@@noextract_to "krml"; norm_field_attr] // proof-only
let union (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields))
= union0 tn #tf n fields
val union_get_case_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
: Lemma
(union_get_case (unknown (union0 tn n fields)) == None)
[SMTPat (unknown (union0 tn n fields))]
val union_set_field_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
: Lemma
(union_set_field tn n fields field (unknown (fields.fd_typedef field)) == unknown (union0 tn n fields))
[SMTPat (union_set_field tn n fields field (unknown (fields.fd_typedef field)))]
val union_get_case_uninitialized
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
: Lemma
(union_get_case (uninitialized (union0 tn n fields)) == None)
[SMTPat (uninitialized (union0 tn n fields))]
val mk_fraction_union_get_case
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(p: perm)
: Lemma
(requires (fractionable (union0 tn n fields) s))
(ensures (
union_get_case (mk_fraction (union0 tn n fields) s p) == union_get_case s
))
[SMTPat (union_get_case (mk_fraction (union0 tn n fields) s p))]
val fractionable_union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
fractionable (union0 tn n fields) s <==> fractionable (fields.fd_typedef field) (union_get_field s field)
))
[SMTPat (fractionable (union0 tn n fields) s); SMTPat (union_get_field s field)]
val mk_fraction_union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(p: perm)
(field: field_t fields)
: Lemma
(requires (fractionable (union0 tn n fields) s /\ union_get_case s == Some field))
(ensures (union_get_field (mk_fraction (union0 tn n fields) s p) field == mk_fraction (fields.fd_typedef field) (union_get_field s field) p))
[SMTPat (union_get_field (mk_fraction (union0 tn n fields) s p) field)]
val mk_fraction_union_set_field
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
(p: perm)
: Lemma
(requires (fractionable (fields.fd_typedef field) v))
(ensures (
fractionable (union0 tn n fields) (union_set_field tn n fields field v) /\
mk_fraction (union0 tn n fields) (union_set_field tn n fields field v) p == union_set_field tn n fields field (mk_fraction (fields.fd_typedef field) v p)
))
val full_union
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
full (union0 tn n fields) s <==> full (fields.fd_typedef field) (union_get_field s field)
))
[SMTPat (full (union0 tn n fields) s); SMTPat (union_get_field s field)]
let full_union_set_field_intro
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (full (fields.fd_typedef field) v))
(ensures (
full (union0 tn n fields) (union_set_field tn n fields field v)
))
= full_union (union_set_field tn n fields field v) field
let full_union_set_field_elim
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (
full (union0 tn n fields) (union_set_field tn n fields field v)
))
(ensures (
full (fields.fd_typedef field) v
))
= full_union (union_set_field tn n fields field v) field
let full_union_set_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires True)
(ensures (
full (union0 tn n fields) (union_set_field tn n fields field v) <==> full (fields.fd_typedef field) v
))
[SMTPat (full (union0 tn n fields) (union_set_field tn n fields field v))]
= Classical.move_requires (full_union_set_field_intro #tn #tf #n #fields field) v;
Classical.move_requires (full_union_set_field_elim #tn #tf #n #fields field) v
val has_union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: Tot vprop
val has_union_field_prop
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r field r')
(fun _ -> has_union_field r field r' ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
val has_union_field_dup
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r field r')
(fun _ -> has_union_field r field r' ** has_union_field r field r')
val has_union_field_inj
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t1: Type0)
(#td1: typedef t1)
(r1: ref td1)
(#t2: Type0)
(#td2: typedef t2)
(r2: ref td2)
: stt_ghost (squash (t1 == t2 /\ td1 == td2))
(has_union_field r field r1 ** has_union_field r field r2)
(fun _ -> has_union_field r field r1 ** has_union_field r field r2 ** ref_equiv r1 (coerce_eq () r2))
val has_union_field_equiv_from
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r1 r2: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r1 field r' ** ref_equiv r1 r2)
(fun _ -> has_union_field r2 field r' ** ref_equiv r1 r2)
val has_union_field_equiv_to
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r1 r2: ref td')
: stt_ghost unit
(has_union_field r field r1 ** ref_equiv r1 r2)
(fun _ -> has_union_field r field r2 ** ref_equiv r1 r2)
val ghost_union_field_focus
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost (squash (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
(has_union_field r field r' ** pts_to r v)
(fun _ -> has_union_field r field r' ** pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field))))
val ghost_union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
: stt_ghost (Ghost.erased (ref (fields.fd_typedef field)))
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
[@@noextract_to "krml"] // primitive
val union_field0
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t' {
t' == fields.fd_type field /\
td' == fields.fd_typedef field
})
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field))))
inline_for_extraction [@@noextract_to "krml"]
let union_field1
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
= union_field0 t' r field td'
inline_for_extraction [@@noextract_to "krml"] // primitive
let union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(#t': Type0)
(#td': typedef t')
(# [ norm_fields () ] sq_t': squash (t' == fields.fd_type field))
(# [ norm_fields () ] sq_td': squash (td' == fields.fd_typedef field))
()
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
= union_field0
t'
r
field
td'
val ununion_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(#v': Ghost.erased t')
(r': ref td')
: stt_ghost (Ghost.erased (union_t0 tn n fields))
(has_union_field r field r' ** pts_to r' v')
(fun res -> has_union_field r field r' ** pts_to r res ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field /\
Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v'))
))
```pulse
ghost
fn ununion_field_and_drop
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(#v': Ghost.erased t')
(r': ref td')
requires
(has_union_field r field r' ** pts_to r' v')
returns res: Ghost.erased (union_t0 tn n fields)
ensures
(pts_to r res ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field /\
Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v'))
))
{
let res = ununion_field r field r';
drop_ (has_union_field r field r');
res
}
```
// NOTE: we DO NOT support preservation of struct prefixes
[@@noextract_to "krml"] // primitive
val union_switch_field0
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(td': typedef t' {
t' == fields.fd_type field /\
td' == fields.fd_typedef field
})
: stt (ref td') // need to write the pcm carrier value, so this cannot be Ghost or Atomic
(pts_to r v ** pure (
full (union0 tn n fields) v
))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td'))
inline_for_extraction [@@noextract_to "krml"]
let union_switch_field1
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td') // need to write the pcm carrier value, so this cannot be Ghost or Atomic
(pts_to r v ** pure (
full (union0 tn n fields) v
))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td'))
= union_switch_field0 t' r field td' | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Union.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Union.union0 tn n fields) ->
field: Pulse.C.Types.Fields.field_t fields ->
_: Prims.unit
-> Pulse.Lib.Core.stt (Pulse.C.Types.Base.ref td')
(Pulse.C.Types.Base.pts_to r v **
Pulse.Lib.Core.pure (Pulse.C.Types.Base.full (Pulse.C.Types.Union.union0 tn n fields)
(FStar.Ghost.reveal v)))
(fun r' ->
Pulse.C.Types.Union.has_union_field r field r' **
Pulse.C.Types.Base.pts_to r' (FStar.Ghost.hide (Pulse.C.Types.Base.uninitialized td'))) | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Pulse.C.Types.Fields.field_description_t",
"FStar.Ghost.erased",
"Pulse.C.Types.Union.union_t0",
"Pulse.C.Types.Base.ref",
"Pulse.C.Types.Union.union0",
"Pulse.C.Types.Fields.field_t",
"Pulse.C.Types.Base.typedef",
"Prims.squash",
"Prims.eq2",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef",
"Prims.unit",
"Pulse.C.Types.Union.union_switch_field0",
"Pulse.Lib.Core.stt",
"Pulse.Lib.Core.op_Star_Star",
"Pulse.C.Types.Base.pts_to",
"Pulse.Lib.Core.pure",
"Pulse.C.Types.Base.full",
"FStar.Ghost.reveal",
"Pulse.C.Types.Union.has_union_field",
"FStar.Ghost.hide",
"Pulse.C.Types.Base.uninitialized",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | false | let union_switch_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field))
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field))
()
: stt (ref td')
(pts_to r v ** pure (full (union0 tn n fields) v))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td')) =
| union_switch_field0 t' r field td' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.slice' | val slice' (#a: Type) (s: seq a) (i: nat) (j: nat{i <= j && j <= length s})
: Tot (seq a) (decreases (length s)) | val slice' (#a: Type) (s: seq a) (i: nat) (j: nat{i <= j && j <= length s})
: Tot (seq a) (decreases (length s)) | let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1)) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 84,
"start_col": 8,
"start_line": 79
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> i: Prims.nat -> j: Prims.nat{i <= j && j <= FStar.Seq.Base.length s}
-> Prims.Tot (FStar.Seq.Base.seq a) | Prims.Tot | [
"total",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_GreaterThan",
"FStar.Seq.Base.slice'",
"FStar.Seq.Base.tl",
"Prims.op_Subtraction",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.MkSeq",
"Prims.Nil",
"FStar.Seq.Base._cons",
"FStar.Seq.Base.hd"
] | [
"recursion"
] | false | false | false | false | false | let rec slice' (#a: Type) (s: seq a) (i: nat) (j: nat{i <= j && j <= length s})
: Tot (seq a) (decreases (length s)) =
| if i > 0
then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq [] else _cons (hd s) (slice' #a (tl s) i (j - 1)) | false |
Hacl.Impl.P256.Point.fsti | Hacl.Impl.P256.Point.getz | val getz (p: point)
: Stack felem
(requires fun h -> live h p)
(ensures fun h0 f h1 -> f == gsub p 8ul 4ul /\ h0 == h1) | val getz (p: point)
: Stack felem
(requires fun h -> live h p)
(ensures fun h0 f h1 -> f == gsub p 8ul 4ul /\ h0 == h1) | let getz (p:point) : Stack felem
(requires fun h -> live h p)
(ensures fun h0 f h1 -> f == gsub p 8ul 4ul /\ h0 == h1)
= sub p 8ul 4ul | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Point.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 124,
"start_col": 0,
"start_line": 121
} | module Hacl.Impl.P256.Point
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
module S = Spec.P256
module SM = Hacl.Spec.P256.Montgomery
module BD = Hacl.Spec.Bignum.Definitions
module LSeq = Lib.Sequence
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0"
let from_mont_point (a:tuple3 nat nat nat) : S.proj_point =
let x, y, z = a in SM.from_mont x, SM.from_mont y, SM.from_mont z
/// Affine coordinates
inline_for_extraction noextract
let aff_point_seq = LSeq.lseq uint64 8
let as_aff_point_nat_seq (p:aff_point_seq) =
BD.bn_v (LSeq.sub p 0 4),
BD.bn_v (LSeq.sub p 4 4)
let aff_point_inv_seq (p:aff_point_seq) =
let x, y = as_aff_point_nat_seq p in
x < S.prime /\ y < S.prime
inline_for_extraction noextract
let aff_point = lbuffer uint64 8ul
noextract
let as_aff_point_nat (h:mem) (p:aff_point) =
as_aff_point_nat_seq (as_seq h p)
noextract
let aff_point_inv (h:mem) (p:aff_point) =
aff_point_inv_seq (as_seq h p)
noextract
let aff_point_x_as_nat (h:mem) (p:aff_point) : GTot nat =
as_nat h (gsub p 0ul 4ul)
noextract
let aff_point_y_as_nat (h:mem) (p:aff_point) : GTot nat =
as_nat h (gsub p 4ul 4ul)
inline_for_extraction noextract
let aff_getx (p:aff_point) : Stack felem
(requires fun h -> live h p)
(ensures fun h0 f h1 -> f == gsub p 0ul 4ul /\ h0 == h1)
= sub p 0ul 4ul
inline_for_extraction noextract
let aff_gety (p:aff_point) : Stack felem
(requires fun h -> live h p)
(ensures fun h0 f h1 -> f == gsub p 4ul 4ul /\ h0 == h1)
= sub p 4ul 4ul
/// Projective coordinates
inline_for_extraction noextract
let point_seq = LSeq.lseq uint64 12
let as_point_nat_seq (p:point_seq) =
BD.bn_v (LSeq.sub p 0 4),
BD.bn_v (LSeq.sub p 4 4),
BD.bn_v (LSeq.sub p 8 4)
let point_inv_seq (p:point_seq) =
let x, y, z = as_point_nat_seq p in
x < S.prime /\ y < S.prime /\ z < S.prime
inline_for_extraction noextract
let point = lbuffer uint64 12ul
noextract
let as_point_nat (h:mem) (p:point) =
as_point_nat_seq (as_seq h p)
noextract
let point_inv (h:mem) (p:point) =
point_inv_seq (as_seq h p)
noextract
let point_x_as_nat (h:mem) (p:point) : GTot nat =
as_nat h (gsub p 0ul 4ul)
noextract
let point_y_as_nat (h:mem) (e:point) : GTot nat =
as_nat h (gsub e 4ul 4ul)
noextract
let point_z_as_nat (h:mem) (e:point) : GTot nat =
as_nat h (gsub e 8ul 4ul)
inline_for_extraction noextract
let getx (p:point) : Stack felem
(requires fun h -> live h p)
(ensures fun h0 f h1 -> f == gsub p 0ul 4ul /\ h0 == h1)
= sub p 0ul 4ul
inline_for_extraction noextract
let gety (p:point) : Stack felem
(requires fun h -> live h p)
(ensures fun h0 f h1 -> f == gsub p 4ul 4ul /\ h0 == h1)
= sub p 4ul 4ul | {
"checked_file": "/",
"dependencies": [
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Point.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"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.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Hacl.Impl.P256.Point.point -> FStar.HyperStack.ST.Stack Hacl.Impl.P256.Bignum.felem | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.P256.Point.point",
"Lib.Buffer.sub",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer_t",
"Hacl.Impl.P256.Bignum.felem",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Prims.l_and",
"Prims.eq2",
"Lib.Buffer.buffer_t",
"Prims.l_or",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Lib.Buffer.length",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Lib.IntTypes.size",
"Lib.Buffer.gsub"
] | [] | false | true | false | false | false | let getz (p: point)
: Stack felem
(requires fun h -> live h p)
(ensures fun h0 f h1 -> f == gsub p 8ul 4ul /\ h0 == h1) =
| sub p 8ul 4ul | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_init_ghost_aux_len | val lemma_init_ghost_aux_len (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
[SMTPat (length (init_aux_ghost n k contents))] | val lemma_init_ghost_aux_len (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
[SMTPat (length (init_aux_ghost n k contents))] | let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 113,
"start_col": 0,
"start_line": 113
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> k: Prims.nat{k < n} -> contents: (i: Prims.nat{i < n} -> Prims.GTot a)
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.length (FStar.Seq.Base.init_aux_ghost n k contents) = n - k)
[SMTPat (FStar.Seq.Base.length (FStar.Seq.Base.init_aux_ghost n k contents))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.lemma_init_ghost_aux_len'"
] | [] | true | false | true | false | false | let lemma_init_ghost_aux_len =
| lemma_init_ghost_aux_len' | false |
Pulse.C.Types.Union.fsti | Pulse.C.Types.Union.union_field | val union_field:
#tn: Type0 ->
#tf: Type0 ->
#n: string ->
#fields: field_description_t tf ->
#v: Ghost.erased (union_t0 tn n fields) ->
r: ref (union0 tn n fields) ->
field: field_t fields {union_get_case v == Some field} ->
#t': Type0 ->
#td': typedef t' ->
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field)) ->
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field)) ->
Prims.unit
-> stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field)) | val union_field:
#tn: Type0 ->
#tf: Type0 ->
#n: string ->
#fields: field_description_t tf ->
#v: Ghost.erased (union_t0 tn n fields) ->
r: ref (union0 tn n fields) ->
field: field_t fields {union_get_case v == Some field} ->
#t': Type0 ->
#td': typedef t' ->
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field)) ->
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field)) ->
Prims.unit
-> stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field)) | let union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(#t': Type0)
(#td': typedef t')
(# [ norm_fields () ] sq_t': squash (t' == fields.fd_type field))
(# [ norm_fields () ] sq_td': squash (td' == fields.fd_typedef field))
()
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
= union_field0
t'
r
field
td' | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Union.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 400,
"start_col": 0,
"start_line": 380
} | module Pulse.C.Types.Union
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
[@@noextract_to "krml"] // primitive
val define_union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_union (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0
= define_union0 tn #tf n fields
// To be extracted as: union t
[@@noextract_to "krml"] // primitive
val union_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let union_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0
= union_t0 tn #tf n fields
val union_set_field (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) (f: field_t fields) (v: fields.fd_type f) : GTot (union_t0 tn n fields)
val union_get_case
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(u: union_t0 tn n fields)
: GTot (option (field_t fields))
val union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(u: union_t0 tn n fields)
(field: field_t fields)
: Ghost (fields.fd_type field)
(requires (union_get_case u == Some field))
(ensures (fun _ -> True))
val union_get_field_same
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (~ (v == unknown (fields.fd_typedef field))))
(ensures (
let u = union_set_field tn n fields field v in
union_get_case u == Some field /\
union_get_field u field == v
))
[SMTPatOr [
[SMTPat (union_get_case (union_set_field tn n fields field v))];
[SMTPat (union_get_field (union_set_field tn n fields field v) field)];
]]
val union_set_field_same
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
union_set_field tn n fields field (union_get_field s field) == s
))
[SMTPat (union_set_field tn n fields (union_get_field s field))]
[@@noextract_to "krml"] // proof-only
val union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields))
inline_for_extraction
[@@noextract_to "krml"; norm_field_attr] // proof-only
let union (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields))
= union0 tn #tf n fields
val union_get_case_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
: Lemma
(union_get_case (unknown (union0 tn n fields)) == None)
[SMTPat (unknown (union0 tn n fields))]
val union_set_field_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
: Lemma
(union_set_field tn n fields field (unknown (fields.fd_typedef field)) == unknown (union0 tn n fields))
[SMTPat (union_set_field tn n fields field (unknown (fields.fd_typedef field)))]
val union_get_case_uninitialized
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
: Lemma
(union_get_case (uninitialized (union0 tn n fields)) == None)
[SMTPat (uninitialized (union0 tn n fields))]
val mk_fraction_union_get_case
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(p: perm)
: Lemma
(requires (fractionable (union0 tn n fields) s))
(ensures (
union_get_case (mk_fraction (union0 tn n fields) s p) == union_get_case s
))
[SMTPat (union_get_case (mk_fraction (union0 tn n fields) s p))]
val fractionable_union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
fractionable (union0 tn n fields) s <==> fractionable (fields.fd_typedef field) (union_get_field s field)
))
[SMTPat (fractionable (union0 tn n fields) s); SMTPat (union_get_field s field)]
val mk_fraction_union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(p: perm)
(field: field_t fields)
: Lemma
(requires (fractionable (union0 tn n fields) s /\ union_get_case s == Some field))
(ensures (union_get_field (mk_fraction (union0 tn n fields) s p) field == mk_fraction (fields.fd_typedef field) (union_get_field s field) p))
[SMTPat (union_get_field (mk_fraction (union0 tn n fields) s p) field)]
val mk_fraction_union_set_field
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
(p: perm)
: Lemma
(requires (fractionable (fields.fd_typedef field) v))
(ensures (
fractionable (union0 tn n fields) (union_set_field tn n fields field v) /\
mk_fraction (union0 tn n fields) (union_set_field tn n fields field v) p == union_set_field tn n fields field (mk_fraction (fields.fd_typedef field) v p)
))
val full_union
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
full (union0 tn n fields) s <==> full (fields.fd_typedef field) (union_get_field s field)
))
[SMTPat (full (union0 tn n fields) s); SMTPat (union_get_field s field)]
let full_union_set_field_intro
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (full (fields.fd_typedef field) v))
(ensures (
full (union0 tn n fields) (union_set_field tn n fields field v)
))
= full_union (union_set_field tn n fields field v) field
let full_union_set_field_elim
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (
full (union0 tn n fields) (union_set_field tn n fields field v)
))
(ensures (
full (fields.fd_typedef field) v
))
= full_union (union_set_field tn n fields field v) field
let full_union_set_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires True)
(ensures (
full (union0 tn n fields) (union_set_field tn n fields field v) <==> full (fields.fd_typedef field) v
))
[SMTPat (full (union0 tn n fields) (union_set_field tn n fields field v))]
= Classical.move_requires (full_union_set_field_intro #tn #tf #n #fields field) v;
Classical.move_requires (full_union_set_field_elim #tn #tf #n #fields field) v
val has_union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: Tot vprop
val has_union_field_prop
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r field r')
(fun _ -> has_union_field r field r' ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
val has_union_field_dup
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r field r')
(fun _ -> has_union_field r field r' ** has_union_field r field r')
val has_union_field_inj
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t1: Type0)
(#td1: typedef t1)
(r1: ref td1)
(#t2: Type0)
(#td2: typedef t2)
(r2: ref td2)
: stt_ghost (squash (t1 == t2 /\ td1 == td2))
(has_union_field r field r1 ** has_union_field r field r2)
(fun _ -> has_union_field r field r1 ** has_union_field r field r2 ** ref_equiv r1 (coerce_eq () r2))
val has_union_field_equiv_from
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r1 r2: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r1 field r' ** ref_equiv r1 r2)
(fun _ -> has_union_field r2 field r' ** ref_equiv r1 r2)
val has_union_field_equiv_to
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r1 r2: ref td')
: stt_ghost unit
(has_union_field r field r1 ** ref_equiv r1 r2)
(fun _ -> has_union_field r field r2 ** ref_equiv r1 r2)
val ghost_union_field_focus
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost (squash (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
(has_union_field r field r' ** pts_to r v)
(fun _ -> has_union_field r field r' ** pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field))))
val ghost_union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
: stt_ghost (Ghost.erased (ref (fields.fd_typedef field)))
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
[@@noextract_to "krml"] // primitive
val union_field0
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t' {
t' == fields.fd_type field /\
td' == fields.fd_typedef field
})
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field))))
inline_for_extraction [@@noextract_to "krml"]
let union_field1
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
= union_field0 t' r field td' | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Union.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Union.union0 tn n fields) ->
field:
Pulse.C.Types.Fields.field_t fields
{ Pulse.C.Types.Union.union_get_case (FStar.Ghost.reveal v) ==
FStar.Pervasives.Native.Some field } ->
_: Prims.unit
-> Pulse.Lib.Core.stt (Pulse.C.Types.Base.ref td')
(Pulse.C.Types.Base.pts_to r v)
(fun r' ->
Pulse.C.Types.Union.has_union_field r field r' **
Pulse.C.Types.Base.pts_to r'
(FStar.Ghost.hide (Pulse.C.Types.Union.union_get_field (FStar.Ghost.reveal v) field))) | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Pulse.C.Types.Fields.field_description_t",
"FStar.Ghost.erased",
"Pulse.C.Types.Union.union_t0",
"Pulse.C.Types.Base.ref",
"Pulse.C.Types.Union.union0",
"Pulse.C.Types.Fields.field_t",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Pulse.C.Types.Union.union_get_case",
"FStar.Ghost.reveal",
"FStar.Pervasives.Native.Some",
"Pulse.C.Types.Base.typedef",
"Prims.squash",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef",
"Prims.unit",
"Pulse.C.Types.Union.union_field0",
"Pulse.Lib.Core.stt",
"Pulse.C.Types.Base.pts_to",
"Pulse.Lib.Core.op_Star_Star",
"Pulse.C.Types.Union.has_union_field",
"FStar.Ghost.hide",
"Pulse.C.Types.Union.union_get_field",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | false | let union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(#t': Type0)
(#td': typedef t')
(#[norm_fields ()] sq_t': squash (t' == fields.fd_type field))
(#[norm_fields ()] sq_td': squash (td' == fields.fd_typedef field))
()
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field)) =
| union_field0 t' r field td' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_len_slice | val lemma_len_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j && j <= length s} -> Lemma
(requires True)
(ensures (length (slice s i j) = j - i))
[SMTPat (length (slice s i j))] | val lemma_len_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j && j <= length s} -> Lemma
(requires True)
(ensures (length (slice s i j) = j - i))
[SMTPat (length (slice s i j))] | let lemma_len_slice = lemma_len_slice' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 127,
"start_col": 0,
"start_line": 127
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> i: Prims.nat -> j: Prims.nat{i <= j && j <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.length (FStar.Seq.Base.slice s i j) = j - i)
[SMTPat (FStar.Seq.Base.length (FStar.Seq.Base.slice s i j))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.lemma_len_slice'"
] | [] | true | false | true | false | false | let lemma_len_slice =
| lemma_len_slice' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_create_len | val lemma_create_len: #a:Type -> n:nat -> i:a -> Lemma
(requires True)
(ensures (length (create n i) = n))
[SMTPat (length (create n i))] | val lemma_create_len: #a:Type -> n:nat -> i:a -> Lemma
(requires True)
(ensures (length (create n i) = n))
[SMTPat (length (create n i))] | let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 82,
"end_line": 93,
"start_col": 0,
"start_line": 93
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> i: a
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.length (FStar.Seq.Base.create n i) = n)
[SMTPat (FStar.Seq.Base.length (FStar.Seq.Base.create n i))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.lemma_create_len",
"Prims.op_Subtraction",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_create_len #_ n i =
| if n = 0 then () else lemma_create_len (n - 1) i | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_init_len | val lemma_init_len: #a:Type -> n:nat -> contents: (i:nat { i < n } -> Tot a) -> Lemma
(requires True)
(ensures (length (init n contents) = n))
[SMTPat (length (init n contents))] | val lemma_init_len: #a:Type -> n:nat -> contents: (i:nat { i < n } -> Tot a) -> Lemma
(requires True)
(ensures (length (init n contents) = n))
[SMTPat (length (init n contents))] | let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 89,
"end_line": 101,
"start_col": 0,
"start_line": 101
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> contents: (i: Prims.nat{i < n} -> a)
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.length (FStar.Seq.Base.init n contents) = n)
[SMTPat (FStar.Seq.Base.length (FStar.Seq.Base.init n contents))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.lemma_init_aux_len'",
"Prims.unit"
] | [] | false | false | true | false | false | let lemma_init_len #_ n contents =
| if n = 0 then () else lemma_init_aux_len' n 0 contents | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_init_ghost_len | val lemma_init_ghost_len: #a:Type -> n:nat -> contents: (i:nat { i < n } -> GTot a) -> Lemma
(requires True)
(ensures (length (init_ghost n contents) = n))
[SMTPat (length (init_ghost n contents))] | val lemma_init_ghost_len: #a:Type -> n:nat -> contents: (i:nat { i < n } -> GTot a) -> Lemma
(requires True)
(ensures (length (init_ghost n contents) = n))
[SMTPat (length (init_ghost n contents))] | let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 101,
"end_line": 111,
"start_col": 0,
"start_line": 111
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> contents: (i: Prims.nat{i < n} -> Prims.GTot a)
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.length (FStar.Seq.Base.init_ghost n contents) = n)
[SMTPat (FStar.Seq.Base.length (FStar.Seq.Base.init_ghost n contents))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.lemma_init_ghost_aux_len'",
"Prims.unit"
] | [] | false | false | true | false | false | let lemma_init_ghost_len #_ n contents =
| if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents | false |
Pulse.C.Types.Union.fsti | Pulse.C.Types.Union.union_switch_field1 | val union_switch_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v ** pure (full (union0 tn n fields) v))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td')) | val union_switch_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v ** pure (full (union0 tn n fields) v))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td')) | let union_switch_field1
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td') // need to write the pcm carrier value, so this cannot be Ghost or Atomic
(pts_to r v ** pure (
full (union0 tn n fields) v
))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td'))
= union_switch_field0 t' r field td' | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Union.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 36,
"end_line": 490,
"start_col": 0,
"start_line": 473
} | module Pulse.C.Types.Union
open Pulse.Lib.Pervasives
include Pulse.C.Types.Fields
open Pulse.C.Typestring
[@@noextract_to "krml"] // primitive
val define_union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let define_union (n: string) (#tf: Type0) (#tn: Type0) (#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0
= define_union0 tn #tf n fields
// To be extracted as: union t
[@@noextract_to "krml"] // primitive
val union_t0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot Type0
inline_for_extraction [@@noextract_to "krml"]
let union_t (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot Type0
= union_t0 tn #tf n fields
val union_set_field (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) (f: field_t fields) (v: fields.fd_type f) : GTot (union_t0 tn n fields)
val union_get_case
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(u: union_t0 tn n fields)
: GTot (option (field_t fields))
val union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(u: union_t0 tn n fields)
(field: field_t fields)
: Ghost (fields.fd_type field)
(requires (union_get_case u == Some field))
(ensures (fun _ -> True))
val union_get_field_same
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (~ (v == unknown (fields.fd_typedef field))))
(ensures (
let u = union_set_field tn n fields field v in
union_get_case u == Some field /\
union_get_field u field == v
))
[SMTPatOr [
[SMTPat (union_get_case (union_set_field tn n fields field v))];
[SMTPat (union_get_field (union_set_field tn n fields field v) field)];
]]
val union_set_field_same
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
union_set_field tn n fields field (union_get_field s field) == s
))
[SMTPat (union_set_field tn n fields (union_get_field s field))]
[@@noextract_to "krml"] // proof-only
val union0 (tn: Type0) (#tf: Type0) (n: string) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields))
inline_for_extraction
[@@noextract_to "krml"; norm_field_attr] // proof-only
let union (#tf: Type0) (n: string) (#tn: Type0) (# [solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == tn))) (fields: field_description_t tf) : Tot (typedef (union_t0 tn n fields))
= union0 tn #tf n fields
val union_get_case_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
: Lemma
(union_get_case (unknown (union0 tn n fields)) == None)
[SMTPat (unknown (union0 tn n fields))]
val union_set_field_unknown
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
: Lemma
(union_set_field tn n fields field (unknown (fields.fd_typedef field)) == unknown (union0 tn n fields))
[SMTPat (union_set_field tn n fields field (unknown (fields.fd_typedef field)))]
val union_get_case_uninitialized
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
: Lemma
(union_get_case (uninitialized (union0 tn n fields)) == None)
[SMTPat (uninitialized (union0 tn n fields))]
val mk_fraction_union_get_case
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(p: perm)
: Lemma
(requires (fractionable (union0 tn n fields) s))
(ensures (
union_get_case (mk_fraction (union0 tn n fields) s p) == union_get_case s
))
[SMTPat (union_get_case (mk_fraction (union0 tn n fields) s p))]
val fractionable_union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
fractionable (union0 tn n fields) s <==> fractionable (fields.fd_typedef field) (union_get_field s field)
))
[SMTPat (fractionable (union0 tn n fields) s); SMTPat (union_get_field s field)]
val mk_fraction_union_get_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(p: perm)
(field: field_t fields)
: Lemma
(requires (fractionable (union0 tn n fields) s /\ union_get_case s == Some field))
(ensures (union_get_field (mk_fraction (union0 tn n fields) s p) field == mk_fraction (fields.fd_typedef field) (union_get_field s field) p))
[SMTPat (union_get_field (mk_fraction (union0 tn n fields) s p) field)]
val mk_fraction_union_set_field
(tn: Type0)
(#tf: Type0)
(n: string)
(fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
(p: perm)
: Lemma
(requires (fractionable (fields.fd_typedef field) v))
(ensures (
fractionable (union0 tn n fields) (union_set_field tn n fields field v) /\
mk_fraction (union0 tn n fields) (union_set_field tn n fields field v) p == union_set_field tn n fields field (mk_fraction (fields.fd_typedef field) v p)
))
val full_union
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(s: union_t0 tn n fields)
(field: field_t fields)
: Lemma
(requires (union_get_case s == Some field))
(ensures (
full (union0 tn n fields) s <==> full (fields.fd_typedef field) (union_get_field s field)
))
[SMTPat (full (union0 tn n fields) s); SMTPat (union_get_field s field)]
let full_union_set_field_intro
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (full (fields.fd_typedef field) v))
(ensures (
full (union0 tn n fields) (union_set_field tn n fields field v)
))
= full_union (union_set_field tn n fields field v) field
let full_union_set_field_elim
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires (
full (union0 tn n fields) (union_set_field tn n fields field v)
))
(ensures (
full (fields.fd_typedef field) v
))
= full_union (union_set_field tn n fields field v) field
let full_union_set_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(field: field_t fields)
(v: fields.fd_type field)
: Lemma
(requires True)
(ensures (
full (union0 tn n fields) (union_set_field tn n fields field v) <==> full (fields.fd_typedef field) v
))
[SMTPat (full (union0 tn n fields) (union_set_field tn n fields field v))]
= Classical.move_requires (full_union_set_field_intro #tn #tf #n #fields field) v;
Classical.move_requires (full_union_set_field_elim #tn #tf #n #fields field) v
val has_union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: Tot vprop
val has_union_field_prop
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r field r')
(fun _ -> has_union_field r field r' ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
val has_union_field_dup
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r field r')
(fun _ -> has_union_field r field r' ** has_union_field r field r')
val has_union_field_inj
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t1: Type0)
(#td1: typedef t1)
(r1: ref td1)
(#t2: Type0)
(#td2: typedef t2)
(r2: ref td2)
: stt_ghost (squash (t1 == t2 /\ td1 == td2))
(has_union_field r field r1 ** has_union_field r field r2)
(fun _ -> has_union_field r field r1 ** has_union_field r field r2 ** ref_equiv r1 (coerce_eq () r2))
val has_union_field_equiv_from
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r1 r2: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost unit
(has_union_field r1 field r' ** ref_equiv r1 r2)
(fun _ -> has_union_field r2 field r' ** ref_equiv r1 r2)
val has_union_field_equiv_to
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: nonempty_field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(r1 r2: ref td')
: stt_ghost unit
(has_union_field r field r1 ** ref_equiv r1 r2)
(fun _ -> has_union_field r field r2 ** ref_equiv r1 r2)
val ghost_union_field_focus
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(#t': Type0)
(#td': typedef t')
(r': ref td')
: stt_ghost (squash (
t' == fields.fd_type field /\
td' == fields.fd_typedef field
))
(has_union_field r field r' ** pts_to r v)
(fun _ -> has_union_field r field r' ** pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field))))
val ghost_union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
: stt_ghost (Ghost.erased (ref (fields.fd_typedef field)))
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
[@@noextract_to "krml"] // primitive
val union_field0
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t' {
t' == fields.fd_type field /\
td' == fields.fd_typedef field
})
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (Ghost.hide (coerce_eq () (union_get_field v field))))
inline_for_extraction [@@noextract_to "krml"]
let union_field1
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
= union_field0 t' r field td'
inline_for_extraction [@@noextract_to "krml"] // primitive
let union_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields {union_get_case v == Some field})
(#t': Type0)
(#td': typedef t')
(# [ norm_fields () ] sq_t': squash (t' == fields.fd_type field))
(# [ norm_fields () ] sq_td': squash (td' == fields.fd_typedef field))
()
: stt (ref td')
(pts_to r v)
(fun r' -> has_union_field r field r' ** pts_to r' (union_get_field v field))
= union_field0
t'
r
field
td'
val ununion_field
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(#v': Ghost.erased t')
(r': ref td')
: stt_ghost (Ghost.erased (union_t0 tn n fields))
(has_union_field r field r' ** pts_to r' v')
(fun res -> has_union_field r field r' ** pts_to r res ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field /\
Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v'))
))
```pulse
ghost
fn ununion_field_and_drop
(#tn: Type0)
(#tf: Type0)
(#n: string)
(#fields: field_description_t tf)
(r: ref (union0 tn n fields))
(field: field_t fields)
(#t': Type0)
(#td': typedef t')
(#v': Ghost.erased t')
(r': ref td')
requires
(has_union_field r field r' ** pts_to r' v')
returns res: Ghost.erased (union_t0 tn n fields)
ensures
(pts_to r res ** pure (
t' == fields.fd_type field /\
td' == fields.fd_typedef field /\
Ghost.reveal res == union_set_field tn n fields field (coerce_eq () (Ghost.reveal v'))
))
{
let res = ununion_field r field r';
drop_ (has_union_field r field r');
res
}
```
// NOTE: we DO NOT support preservation of struct prefixes
[@@noextract_to "krml"] // primitive
val union_switch_field0
(#tn: Type0)
(#tf: Type0)
(t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(td': typedef t' {
t' == fields.fd_type field /\
td' == fields.fd_typedef field
})
: stt (ref td') // need to write the pcm carrier value, so this cannot be Ghost or Atomic
(pts_to r v ** pure (
full (union0 tn n fields) v
))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td')) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Fields.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Union.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t': Type0 ->
r: Pulse.C.Types.Base.ref (Pulse.C.Types.Union.union0 tn n fields) ->
field: Pulse.C.Types.Fields.field_t fields ->
td': Pulse.C.Types.Base.typedef t' ->
sq_t': Prims.squash (t' == Mkfield_description_t?.fd_type fields field) ->
sq_td': Prims.squash (td' == Mkfield_description_t?.fd_typedef fields field)
-> Pulse.Lib.Core.stt (Pulse.C.Types.Base.ref td')
(Pulse.C.Types.Base.pts_to r v **
Pulse.Lib.Core.pure (Pulse.C.Types.Base.full (Pulse.C.Types.Union.union0 tn n fields)
(FStar.Ghost.reveal v)))
(fun r' ->
Pulse.C.Types.Union.has_union_field r field r' **
Pulse.C.Types.Base.pts_to r' (FStar.Ghost.hide (Pulse.C.Types.Base.uninitialized td'))) | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Pulse.C.Types.Fields.field_description_t",
"FStar.Ghost.erased",
"Pulse.C.Types.Union.union_t0",
"Pulse.C.Types.Base.ref",
"Pulse.C.Types.Union.union0",
"Pulse.C.Types.Fields.field_t",
"Pulse.C.Types.Base.typedef",
"Prims.squash",
"Prims.eq2",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef",
"Pulse.C.Types.Union.union_switch_field0",
"Pulse.Lib.Core.stt",
"Pulse.Lib.Core.op_Star_Star",
"Pulse.C.Types.Base.pts_to",
"Pulse.Lib.Core.pure",
"Pulse.C.Types.Base.full",
"FStar.Ghost.reveal",
"Pulse.C.Types.Union.has_union_field",
"FStar.Ghost.hide",
"Pulse.C.Types.Base.uninitialized",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | false | let union_switch_field1
(#tn #tf t': Type0)
(#n: string)
(#fields: field_description_t tf)
(#v: Ghost.erased (union_t0 tn n fields))
(r: ref (union0 tn n fields))
(field: field_t fields)
(td': typedef t')
(sq_t': squash (t' == fields.fd_type field))
(sq_td': squash (td' == fields.fd_typedef field))
: stt (ref td')
(pts_to r v ** pure (full (union0 tn n fields) v))
(fun r' -> has_union_field r field r' ** pts_to r' (uninitialized td')) =
| union_switch_field0 t' r field td' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_init_ghost_aux_len' | val lemma_init_ghost_aux_len'
(#a: Type)
(n: nat)
(k: nat{k < n})
(contents: (i: nat{i < n} -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n - k)) | val lemma_init_ghost_aux_len'
(#a: Type)
(n: nat)
(k: nat{k < n})
(contents: (i: nat{i < n} -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n - k)) | let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 73,
"end_line": 109,
"start_col": 8,
"start_line": 105
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> k: Prims.nat{k < n} -> contents: (i: Prims.nat{i < n} -> Prims.GTot a)
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.length (FStar.Seq.Base.init_aux_ghost n k contents) = n - k)
(decreases n - k) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"FStar.Seq.Base.lemma_init_ghost_aux_len'",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Seq.Base.length",
"FStar.Seq.Base.init_aux_ghost",
"Prims.op_Subtraction",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_init_ghost_aux_len'
(#a: Type)
(n: nat)
(k: nat{k < n})
(contents: (i: nat{i < n} -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n - k)) =
| if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k + 1) contents | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_init_aux_len' | val lemma_init_aux_len' (#a: Type) (n: nat) (k: nat{k < n}) (contents: (i: nat{i < n} -> Tot a))
: Lemma (requires True) (ensures (length (init_aux n k contents) = n - k)) (decreases (n - k)) | val lemma_init_aux_len' (#a: Type) (n: nat) (k: nat{k < n}) (contents: (i: nat{i < n} -> Tot a))
: Lemma (requires True) (ensures (length (init_aux n k contents) = n - k)) (decreases (n - k)) | let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 67,
"end_line": 99,
"start_col": 0,
"start_line": 95
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> k: Prims.nat{k < n} -> contents: (i: Prims.nat{i < n} -> a)
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.length (FStar.Seq.Base.init_aux n k contents) = n - k)
(decreases n - k) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"FStar.Seq.Base.lemma_init_aux_len'",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Seq.Base.length",
"FStar.Seq.Base.init_aux",
"Prims.op_Subtraction",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_init_aux_len' (#a: Type) (n: nat) (k: nat{k < n}) (contents: (i: nat{i < n} -> Tot a))
: Lemma (requires True) (ensures (length (init_aux n k contents) = n - k)) (decreases (n - k)) =
| if k + 1 = n then () else lemma_init_aux_len' #a n (k + 1) contents | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_len_append | val lemma_len_append: #a:Type -> s1:seq a -> s2:seq a -> Lemma
(requires True)
(ensures (length (append s1 s2) = length s1 + length s2))
[SMTPat (length (append s1 s2))] | val lemma_len_append: #a:Type -> s1:seq a -> s2:seq a -> Lemma
(requires True)
(ensures (length (append s1 s2) = length s1 + length s2))
[SMTPat (length (append s1 s2))] | let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 88,
"end_line": 117,
"start_col": 0,
"start_line": 117
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.length (FStar.Seq.Base.append s1 s2) =
FStar.Seq.Base.length s1 + FStar.Seq.Base.length s2)
[SMTPat (FStar.Seq.Base.length (FStar.Seq.Base.append s1 s2))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.List.Tot.Properties.append_length",
"FStar.Seq.Base.__proj__MkSeq__item__l",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_len_append #_ s1 s2 =
| FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_upd2 | val lemma_index_upd2: #a:Type -> s:seq a -> n:nat{n < length s} -> v:a -> i:nat{i<>n /\ i < length s} -> Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
[SMTPat (index (upd s n v) i)] | val lemma_index_upd2: #a:Type -> s:seq a -> n:nat{n < length s} -> v:a -> i:nat{i<>n /\ i < length s} -> Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
[SMTPat (index (upd s n v) i)] | let lemma_index_upd2 = lemma_index_upd2' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 160,
"start_col": 0,
"start_line": 160
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq a ->
n: Prims.nat{n < FStar.Seq.Base.length s} ->
v: a ->
i: Prims.nat{i <> n /\ i < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.index (FStar.Seq.Base.upd s n v) i == FStar.Seq.Base.index s i)
[SMTPat (FStar.Seq.Base.index (FStar.Seq.Base.upd s n v) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.lemma_index_upd2'"
] | [] | true | false | true | false | false | let lemma_index_upd2 =
| lemma_index_upd2' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_upd1 | val lemma_index_upd1: #a:Type -> s:seq a -> n:nat{n < length s} -> v:a -> Lemma
(requires True)
(ensures (index (upd s n v) n == v))
[SMTPat (index (upd s n v) n)] | val lemma_index_upd1: #a:Type -> s:seq a -> n:nat{n < length s} -> v:a -> Lemma
(requires True)
(ensures (index (upd s n v) n == v))
[SMTPat (index (upd s n v) n)] | let lemma_index_upd1 = lemma_index_upd1' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 145,
"start_col": 0,
"start_line": 145
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> n: Prims.nat{n < FStar.Seq.Base.length s} -> v: a
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index (FStar.Seq.Base.upd s n v) n == v)
[SMTPat (FStar.Seq.Base.index (FStar.Seq.Base.upd s n v) n)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.lemma_index_upd1'"
] | [] | true | false | true | false | false | let lemma_index_upd1 =
| lemma_index_upd1' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_len_slice' | val lemma_len_slice' (#a: Type) (s: seq a) (i: nat) (j: nat{i <= j && j <= length s})
: Lemma (requires True) (ensures (length (slice s i j) = j - i)) (decreases (length s)) | val lemma_len_slice' (#a: Type) (s: seq a) (i: nat) (j: nat{i <= j && j <= length s})
: Lemma (requires True) (ensures (length (slice s i j) = j - i)) (decreases (length s)) | let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 125,
"start_col": 0,
"start_line": 119
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> i: Prims.nat -> j: Prims.nat{i <= j && j <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.length (FStar.Seq.Base.slice s i j) = j - i)
(decreases FStar.Seq.Base.length s) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_GreaterThan",
"FStar.Seq.Base.lemma_len_slice'",
"FStar.Seq.Base.tl",
"Prims.op_Subtraction",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Seq.Base.slice",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_len_slice' (#a: Type) (s: seq a) (i: nat) (j: nat{i <= j && j <= length s})
: Lemma (requires True) (ensures (length (slice s i j) = j - i)) (decreases (length s)) =
| if i > 0
then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then () else lemma_len_slice' #a (tl s) i (j - 1) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_len_upd | val lemma_len_upd: #a:Type -> n:nat -> v:a -> s:seq a{n < length s} -> Lemma
(requires True)
(ensures (length (upd s n v) = length s))
[SMTPat (length (upd s n v))] | val lemma_len_upd: #a:Type -> n:nat -> v:a -> s:seq a{n < length s} -> Lemma
(requires True)
(ensures (length (upd s n v) = length s))
[SMTPat (length (upd s n v))] | let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 85,
"end_line": 115,
"start_col": 0,
"start_line": 115
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> v: a -> s: FStar.Seq.Base.seq a {n < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.length (FStar.Seq.Base.upd s n v) = FStar.Seq.Base.length s)
[SMTPat (FStar.Seq.Base.length (FStar.Seq.Base.upd s n v))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.lemma_len_upd",
"Prims.op_Subtraction",
"FStar.Seq.Base.tl",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_len_upd #_ n v s =
| if n = 0 then () else lemma_len_upd (n - 1) v (tl s) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_create | val lemma_index_create: #a:Type -> n:nat -> v:a -> i:nat{i < n} -> Lemma
(requires True)
(ensures (index (create n v) i == v))
[SMTPat (index (create n v) i)] | val lemma_index_create: #a:Type -> n:nat -> v:a -> i:nat{i < n} -> Lemma
(requires True)
(ensures (index (create n v) i == v))
[SMTPat (index (create n v) i)] | let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1)) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 78,
"end_line": 132,
"start_col": 0,
"start_line": 129
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> v: a -> i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index (FStar.Seq.Base.create n v) i == v)
[SMTPat (FStar.Seq.Base.index (FStar.Seq.Base.create n v) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.lemma_index_create",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Seq.Base.lemma_create_len"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_index_create #_ n v i =
| if n = 0
then ()
else
if i = 0
then ()
else
(lemma_create_len (n - 1) v;
lemma_index_create (n - 1) v (i - 1)) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_upd1' | val lemma_index_upd1' (#a: Type) (s: seq a) (n: nat{n < length s}) (v: a)
: Lemma (requires True) (ensures (index (upd s n v) n == v)) (decreases (length s)) | val lemma_index_upd1' (#a: Type) (s: seq a) (n: nat{n < length s}) (v: a)
: Lemma (requires True) (ensures (index (upd s n v) n == v)) (decreases (length s)) | let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 143,
"start_col": 0,
"start_line": 134
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> n: Prims.nat{n < FStar.Seq.Base.length s} -> v: a
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index (FStar.Seq.Base.upd s n v) n == v)
(decreases FStar.Seq.Base.length s) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.upd",
"FStar.Seq.Base.tl",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Seq.Base.lemma_index_upd1'",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_index_upd1' (#a: Type) (s: seq a) (n: nat{n < length s}) (v: a)
: Lemma (requires True) (ensures (index (upd s n v) n == v)) (decreases (length s)) =
| if n = 0
then ()
else
(lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n - 1) v) (n - 1) == v)) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_app2' | val lemma_index_app2'
(#a: Type)
(s1 s2: seq a)
(i: nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma (requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1)))
(decreases (length s1)) | val lemma_index_app2'
(#a: Type)
(s1 s2: seq a)
(i: nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma (requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1)))
(decreases (length s1)) | let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 180,
"start_col": 0,
"start_line": 174
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
i:
Prims.nat
{i < FStar.Seq.Base.length s1 + FStar.Seq.Base.length s2 /\ FStar.Seq.Base.length s1 <= i}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.Seq.Base.append s1 s2) i ==
FStar.Seq.Base.index s2 (i - FStar.Seq.Base.length s1)) (decreases FStar.Seq.Base.length s1) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.__proj__MkSeq__item__l",
"Prims.list",
"FStar.Seq.Base.lemma_index_app2'",
"FStar.Seq.Base.MkSeq",
"Prims.op_Subtraction",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_index_app2'
(#a: Type)
(s1 s2: seq a)
(i: nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma (requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1)))
(decreases (length s1)) =
| match s1.l with
| [] -> ()
| hd :: tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_app1 | val lemma_index_app1: #a:Type -> s1:seq a -> s2:seq a -> i:nat{i < length s1} -> Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i))
[SMTPat (index (append s1 s2) i)] | val lemma_index_app1: #a:Type -> s1:seq a -> s2:seq a -> i:nat{i < length s1} -> Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i))
[SMTPat (index (append s1 s2) i)] | let lemma_index_app1 = lemma_index_app1' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 172,
"start_col": 0,
"start_line": 172
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> i: Prims.nat{i < FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.index (FStar.Seq.Base.append s1 s2) i == FStar.Seq.Base.index s1 i)
[SMTPat (FStar.Seq.Base.index (FStar.Seq.Base.append s1 s2) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.lemma_index_app1'"
] | [] | true | false | true | false | false | let lemma_index_app1 =
| lemma_index_app1' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_app2 | val lemma_index_app2: #a:Type -> s1:seq a -> s2:seq a -> i:nat{i < length s1 + length s2 /\ length s1 <= i} -> Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1)))
[SMTPat (index (append s1 s2) i)] | val lemma_index_app2: #a:Type -> s1:seq a -> s2:seq a -> i:nat{i < length s1 + length s2 /\ length s1 <= i} -> Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1)))
[SMTPat (index (append s1 s2) i)] | let lemma_index_app2 = lemma_index_app2' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 182,
"start_col": 0,
"start_line": 182
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a ->
i:
Prims.nat
{i < FStar.Seq.Base.length s1 + FStar.Seq.Base.length s2 /\ FStar.Seq.Base.length s1 <= i}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.Seq.Base.append s1 s2) i ==
FStar.Seq.Base.index s2 (i - FStar.Seq.Base.length s1))
[SMTPat (FStar.Seq.Base.index (FStar.Seq.Base.append s1 s2) i)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.lemma_index_app2'"
] | [] | true | false | true | false | false | let lemma_index_app2 =
| lemma_index_app2' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_upd2' | val lemma_index_upd2'
(#a: Type)
(s: seq a)
(n: nat{n < length s})
(v: a)
(i: nat{i <> n /\ i < length s})
: Lemma (requires True) (ensures (index (upd s n v) i == index s i)) (decreases (length s)) | val lemma_index_upd2'
(#a: Type)
(s: seq a)
(n: nat{n < length s})
(v: a)
(i: nat{i <> n /\ i < length s})
: Lemma (requires True) (ensures (index (upd s n v) i == index s i)) (decreases (length s)) | let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1)) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 98,
"end_line": 158,
"start_col": 0,
"start_line": 147
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq a ->
n: Prims.nat{n < FStar.Seq.Base.length s} ->
v: a ->
i: Prims.nat{i <> n /\ i < FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.index (FStar.Seq.Base.upd s n v) i == FStar.Seq.Base.index s i)
(decreases FStar.Seq.Base.length s) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.op_disEquality",
"FStar.Seq.Base.__proj__MkSeq__item__l",
"Prims.list",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.lemma_index_upd2'",
"FStar.Seq.Base.MkSeq",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Seq.Base.lemma_len_upd",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.upd",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_index_upd2'
(#a: Type)
(s: seq a)
(n: nat{n < length s})
(v: a)
(i: nat{i <> n /\ i < length s})
: Lemma (requires True) (ensures (index (upd s n v) i == index s i)) (decreases (length s)) =
| match (MkSeq?.l s) with
| [] -> ()
| hd :: tl ->
if i = 0
then ()
else
if n = 0
then ()
else
(lemma_len_upd (n - 1) v (MkSeq tl);
lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1)) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_app1' | val lemma_index_app1' (#a: Type) (s1 s2: seq a) (i: nat{i < length s1})
: Lemma (requires True) (ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1)) | val lemma_index_app1' (#a: Type) (s1 s2: seq a) (i: nat{i < length s1})
: Lemma (requires True) (ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1)) | let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1)) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 85,
"end_line": 170,
"start_col": 0,
"start_line": 162
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> i: Prims.nat{i < FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.index (FStar.Seq.Base.append s1 s2) i == FStar.Seq.Base.index s1 i)
(decreases FStar.Seq.Base.length s1) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"FStar.Seq.Base.__proj__MkSeq__item__l",
"Prims.list",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.lemma_index_app1'",
"FStar.Seq.Base.MkSeq",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Seq.Base.lemma_len_append",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_index_app1' (#a: Type) (s1 s2: seq a) (i: nat{i < length s1})
: Lemma (requires True) (ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1)) =
| match (MkSeq?.l s1) with
| [] -> ()
| hd :: tl ->
if i = 0
then ()
else
(lemma_len_append (MkSeq tl) s2;
lemma_index_app1' #a (MkSeq tl) s2 (i - 1)) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.eq_i | val eq_i:
#a:eqtype -> s1:seq a -> s2:seq a{length s1 = length s2}
-> i:nat{i <= length s1}
-> Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))}) | val eq_i:
#a:eqtype -> s1:seq a -> s2:seq a{length s1 = length s2}
-> i:nat{i <= length s1}
-> Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))}) | let eq_i = eq_i' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 16,
"end_line": 226,
"start_col": 0,
"start_line": 226
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a {FStar.Seq.Base.length s1 = FStar.Seq.Base.length s2} ->
i: Prims.nat{i <= FStar.Seq.Base.length s1}
-> r:
Prims.bool
{ r <==>
(forall (j:
i:
Prims.int
{i >= 0 /\ i < FStar.Seq.Base.length s2 /\ (i >= 0) /\ (i < FStar.Seq.Base.length s1)})
.
j >= i /\ j < FStar.Seq.Base.length s1 ==>
FStar.Seq.Base.index s1 j = FStar.Seq.Base.index s2 j) } | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.eq_i'"
] | [] | false | false | false | false | false | let eq_i =
| eq_i' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.eq | val eq: #a:eqtype -> s1:seq a -> s2:seq a -> Tot (r:bool{r <==> equal s1 s2}) | val eq: #a:eqtype -> s1:seq a -> s2:seq a -> Tot (r:bool{r <==> equal s1 s2}) | let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 228,
"start_col": 0,
"start_line": 228
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a
-> r: Prims.bool{r <==> FStar.Seq.Base.equal s1 s2} | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.Seq.Base.eq_i",
"Prims.bool",
"Prims.l_iff",
"Prims.b2t",
"FStar.Seq.Base.equal"
] | [] | false | false | false | false | false | let eq #_ s1 s2 =
| if length s1 = length s2 then eq_i s1 s2 0 else false | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_slice0' | val lemma_index_slice0' (#a: Type) (s: seq a) (j: nat{j <= length s}) (k: nat{k < j})
: Lemma (requires True) (ensures (index (slice s 0 j) k == index s k)) (decreases (length s)) | val lemma_index_slice0' (#a: Type) (s: seq a) (j: nat{j <= length s}) (k: nat{k < j})
: Lemma (requires True) (ensures (index (slice s 0 j) k == index s k)) (decreases (length s)) | let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 190,
"start_col": 0,
"start_line": 184
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> j: Prims.nat{j <= FStar.Seq.Base.length s} -> k: Prims.nat{k < j}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.index (FStar.Seq.Base.slice s 0 j) k == FStar.Seq.Base.index s k)
(decreases FStar.Seq.Base.length s) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.lemma_index_slice0'",
"FStar.Seq.Base.tl",
"Prims.op_Subtraction",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.slice",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_index_slice0' (#a: Type) (s: seq a) (j: nat{j <= length s}) (k: nat{k < j})
: Lemma (requires True) (ensures (index (slice s 0 j) k == index s k)) (decreases (length s)) =
| if k = 0 then () else lemma_index_slice0' (tl s) (j - 1) (k - 1) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.equal | val equal (#a:Type) (s1:seq a) (s2:seq a) : Tot prop | val equal (#a:Type) (s1:seq a) (s2:seq a) : Tot prop | let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i))) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 103,
"end_line": 216,
"start_col": 0,
"start_line": 214
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.prop"
] | [] | false | false | false | true | true | let equal #a s1 s2 =
| (length s1 = length s2 /\
(forall (i: nat{i < length s1}). {:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i))
) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_slice | val lemma_index_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j /\ j <= length s} -> k:nat{k < j - i} -> Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i)))
[SMTPat (index (slice s i j) k)] | val lemma_index_slice: #a:Type -> s:seq a -> i:nat -> j:nat{i <= j /\ j <= length s} -> k:nat{k < j - i} -> Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i)))
[SMTPat (index (slice s i j) k)] | let lemma_index_slice = lemma_index_slice' | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 210,
"start_col": 0,
"start_line": 210
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq a ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j <= FStar.Seq.Base.length s} ->
k: Prims.nat{k < j - i}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.index (FStar.Seq.Base.slice s i j) k == FStar.Seq.Base.index s (k + i)
) [SMTPat (FStar.Seq.Base.index (FStar.Seq.Base.slice s i j) k)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.lemma_index_slice'"
] | [] | true | false | true | false | false | let lemma_index_slice =
| lemma_index_slice' | false |
FStar.Seq.Base.fst | FStar.Seq.Base.append_assoc | val append_assoc
(#a: Type)
(s1 s2 s3: seq a)
: Lemma
(ensures (append (append s1 s2) s3 == append s1 (append s2 s3))) | val append_assoc
(#a: Type)
(s1 s2 s3: seq a)
: Lemma
(ensures (append (append s1 s2) s3 == append s1 (append s2 s3))) | let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 90,
"end_line": 243,
"start_col": 0,
"start_line": 243
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> s3: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.append (FStar.Seq.Base.append s1 s2) s3 ==
FStar.Seq.Base.append s1 (FStar.Seq.Base.append s2 s3)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.List.Tot.Properties.append_assoc",
"FStar.Seq.Base.__proj__MkSeq__item__l",
"Prims.unit"
] | [] | true | false | true | false | false | let append_assoc #a s1 s2 s3 =
| List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_index_slice' | val lemma_index_slice'
(#a: Type)
(s: seq a)
(i: nat)
(j: nat{i <= j /\ j <= length s})
(k: nat{k < j - i})
: Lemma (requires True)
(ensures (index (slice s i j) k == index s (k + i)))
(decreases (length s)) | val lemma_index_slice'
(#a: Type)
(s: seq a)
(i: nat)
(j: nat{i <= j /\ j <= length s})
(k: nat{k < j - i})
: Lemma (requires True)
(ensures (index (slice s i j) k == index s (k + i)))
(decreases (length s)) | let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 207,
"start_col": 0,
"start_line": 193
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq a ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j <= FStar.Seq.Base.length s} ->
k: Prims.nat{k < j - i}
-> FStar.Pervasives.Lemma
(ensures FStar.Seq.Base.index (FStar.Seq.Base.slice s i j) k == FStar.Seq.Base.index s (k + i)
) (decreases FStar.Seq.Base.length s) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.op_GreaterThan",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.unit",
"FStar.Seq.Base.tl",
"FStar.Seq.Base.lemma_index_slice'",
"Prims.bool",
"FStar.Seq.Base.lemma_index_slice0'",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_index_slice'
(#a: Type)
(s: seq a)
(i: nat)
(j: nat{i <= j /\ j <= length s})
(k: nat{k < j - i})
: Lemma (requires True)
(ensures (index (slice s i j) k == index s (k + i)))
(decreases (length s)) =
| if i > 0
then
(lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i)))
else
(assert (j > 0);
lemma_index_slice0' #a s j k) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.lemma_eq_elim | val lemma_eq_elim: #a:Type -> s1:seq a -> s2:seq a -> Lemma
(requires (equal s1 s2))
(ensures (s1==s2))
[SMTPat (equal s1 s2)] | val lemma_eq_elim: #a:Type -> s1:seq a -> s2:seq a -> Lemma
(requires (equal s1 s2))
(ensures (s1==s2))
[SMTPat (equal s1 s2)] | let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 239,
"start_col": 0,
"start_line": 234
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.equal s1 s2)
(ensures s1 == s2)
[SMTPat (FStar.Seq.Base.equal s1 s2)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.List.Tot.Properties.index_extensionality",
"FStar.Seq.Base.__proj__MkSeq__item__l",
"Prims.unit",
"Prims._assert",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.List.Tot.Base.index",
"FStar.List.Tot.Base.length"
] | [] | false | false | true | false | false | let lemma_eq_elim #_ s1 s2 =
| assert (length s1 == List.length (MkSeq?.l s1));
assert (length s2 == List.length (MkSeq?.l s2));
assert (forall (i: nat). i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert (forall (i: nat). i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.append_empty_l | val append_empty_l
(#a: Type)
(s: seq a)
: Lemma
(ensures (append empty s == s)) | val append_empty_l
(#a: Type)
(s: seq a)
: Lemma
(ensures (append empty s == s)) | let append_empty_l #a s = List.append_nil_l (MkSeq?.l s) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 245,
"start_col": 0,
"start_line": 245
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *)
let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.append FStar.Seq.Base.empty s == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.List.Tot.Properties.append_nil_l",
"FStar.Seq.Base.__proj__MkSeq__item__l",
"Prims.unit"
] | [] | true | false | true | false | false | let append_empty_l #a s =
| List.append_nil_l (MkSeq?.l s) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.append_empty_r | val append_empty_r
(#a: Type)
(s: seq a)
: Lemma
(ensures (append s empty == s)) | val append_empty_r
(#a: Type)
(s: seq a)
: Lemma
(ensures (append s empty == s)) | let append_empty_r #a s = List.append_l_nil (MkSeq?.l s) | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 247,
"start_col": 0,
"start_line": 247
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *)
let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3)
let append_empty_l #a s = List.append_nil_l (MkSeq?.l s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.append s FStar.Seq.Base.empty == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.List.Tot.Properties.append_l_nil",
"FStar.Seq.Base.__proj__MkSeq__item__l",
"Prims.unit"
] | [] | true | false | true | false | false | let append_empty_r #a s =
| List.append_l_nil (MkSeq?.l s) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.eq_i' | val eq_i' (#a: eqtype) (s1: seq a) (s2: seq a {length s1 == length s2}) (i: nat{i <= length s1})
: Tot (r: bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i)) | val eq_i' (#a: eqtype) (s1: seq a) (s2: seq a {length s1 == length s2}) (i: nat{i <= length s1})
: Tot (r: bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i)) | let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 14,
"end_line": 224,
"start_col": 0,
"start_line": 218
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a {FStar.Seq.Base.length s1 == FStar.Seq.Base.length s2} ->
i: Prims.nat{i <= FStar.Seq.Base.length s1}
-> Prims.Tot
(r:
Prims.bool
{ r <==>
(forall (j:
i:
Prims.int
{ i >= 0 /\ i < FStar.Seq.Base.length s2 /\
(i >= 0) /\ (i < FStar.Seq.Base.length s1) }).
j >= i /\ j < FStar.Seq.Base.length s1 ==>
FStar.Seq.Base.index s1 j = FStar.Seq.Base.index s2 j) }) | Prims.Tot | [
"total",
""
] | [] | [
"Prims.eqtype",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.bool",
"FStar.Seq.Base.index",
"FStar.Seq.Base.eq_i'",
"Prims.op_Addition",
"Prims.l_iff",
"Prims.l_Forall",
"Prims.int",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"Prims.l_imp"
] | [
"recursion"
] | false | false | false | false | false | let rec eq_i' (#a: eqtype) (s1: seq a) (s2: seq a {length s1 == length s2}) (i: nat{i <= length s1})
: Tot (r: bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i)) =
| if i = length s1 then true else if index s1 i = index s2 i then eq_i' s1 s2 (i + 1) else false | false |
FStar.Seq.Base.fst | FStar.Seq.Base.init_ghost_index_ | val init_ghost_index_ (#a:Type) (len:nat) (contents:(i:nat { i < len } -> GTot a)) (j: nat)
: Lemma (requires j < len)
(ensures (index (init_ghost len contents) j == contents j))
[SMTPat (index (init_ghost len contents) j)] | val init_ghost_index_ (#a:Type) (len:nat) (contents:(i:nat { i < len } -> GTot a)) (j: nat)
: Lemma (requires j < len)
(ensures (index (init_ghost len contents) j == contents j))
[SMTPat (index (init_ghost len contents) j)] | let init_ghost_index_ #_ len contents j = init_ghost_index len contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 71,
"end_line": 288,
"start_col": 0,
"start_line": 288
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *)
let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3)
let append_empty_l #a s = List.append_nil_l (MkSeq?.l s)
let append_empty_r #a s = List.append_l_nil (MkSeq?.l s)
private
let rec init_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> Tot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux len k contents) 0 == contents k
else index (init_aux len k contents) i == index (init_aux len (k+1) contents) (i-1))
end
let init_index #_ len contents =
if len = 0 then () else init_index_aux len 0 contents
let init_index_ #_ len contents j = init_index len contents
private
let rec init_ghost_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux_ghost len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_ghost_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux_ghost len k contents) 0 == contents k
else index (init_aux_ghost len k contents) i == index (init_aux_ghost len (k+1) contents) (i-1))
end
let init_ghost_index #_ len contents =
if len = 0 then () else init_ghost_index_aux len 0 contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Prims.nat -> contents: (i: Prims.nat{i < len} -> Prims.GTot a) -> j: Prims.nat
-> FStar.Pervasives.Lemma (requires j < len)
(ensures FStar.Seq.Base.index (FStar.Seq.Base.init_ghost len contents) j == contents j)
[SMTPat (FStar.Seq.Base.index (FStar.Seq.Base.init_ghost len contents) j)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.init_ghost_index",
"Prims.unit"
] | [] | true | false | true | false | false | let init_ghost_index_ #_ len contents j =
| init_ghost_index len contents | false |
FStar.Seq.Base.fst | FStar.Seq.Base.init_index_ | val init_index_ (#a:Type) (len:nat) (contents:(i:nat { i < len } -> Tot a)) (j: nat)
: Lemma (requires j < len)
(ensures (index (init len contents) j == contents j))
[SMTPat (index (init len contents) j)] | val init_index_ (#a:Type) (len:nat) (contents:(i:nat { i < len } -> Tot a)) (j: nat)
: Lemma (requires j < len)
(ensures (index (init len contents) j == contents j))
[SMTPat (index (init len contents) j)] | let init_index_ #_ len contents j = init_index len contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 268,
"start_col": 0,
"start_line": 268
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *)
let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3)
let append_empty_l #a s = List.append_nil_l (MkSeq?.l s)
let append_empty_r #a s = List.append_l_nil (MkSeq?.l s)
private
let rec init_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> Tot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux len k contents) 0 == contents k
else index (init_aux len k contents) i == index (init_aux len (k+1) contents) (i-1))
end
let init_index #_ len contents =
if len = 0 then () else init_index_aux len 0 contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Prims.nat -> contents: (i: Prims.nat{i < len} -> a) -> j: Prims.nat
-> FStar.Pervasives.Lemma (requires j < len)
(ensures FStar.Seq.Base.index (FStar.Seq.Base.init len contents) j == contents j)
[SMTPat (FStar.Seq.Base.index (FStar.Seq.Base.init len contents) j)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.init_index",
"Prims.unit"
] | [] | true | false | true | false | false | let init_index_ #_ len contents j =
| init_index len contents | false |
FStar.Seq.Base.fst | FStar.Seq.Base.init_index | val init_index (#a:Type) (len:nat) (contents:(i:nat { i < len } -> Tot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len}). index (init len contents) i == contents i)) | val init_index (#a:Type) (len:nat) (contents:(i:nat { i < len } -> Tot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len}). index (init len contents) i == contents i)) | let init_index #_ len contents =
if len = 0 then () else init_index_aux len 0 contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 266,
"start_col": 0,
"start_line": 265
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *)
let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3)
let append_empty_l #a s = List.append_nil_l (MkSeq?.l s)
let append_empty_r #a s = List.append_l_nil (MkSeq?.l s)
private
let rec init_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> Tot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux len k contents) 0 == contents k
else index (init_aux len k contents) i == index (init_aux len (k+1) contents) (i-1))
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Prims.nat -> contents: (i: Prims.nat{i < len} -> a)
-> FStar.Pervasives.Lemma
(ensures
forall (i: Prims.nat{i < len}).
FStar.Seq.Base.index (FStar.Seq.Base.init len contents) i == contents i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.init_index_aux",
"Prims.unit"
] | [] | false | false | true | false | false | let init_index #_ len contents =
| if len = 0 then () else init_index_aux len 0 contents | false |
FStar.Seq.Base.fst | FStar.Seq.Base.init_ghost_index | val init_ghost_index (#a:Type) (len:nat) (contents:(i:nat { i < len } -> GTot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len}). index (init_ghost len contents) i == contents i)) | val init_ghost_index (#a:Type) (len:nat) (contents:(i:nat { i < len } -> GTot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len}). index (init_ghost len contents) i == contents i)) | let init_ghost_index #_ len contents =
if len = 0 then () else init_ghost_index_aux len 0 contents | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 286,
"start_col": 0,
"start_line": 285
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *)
let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3)
let append_empty_l #a s = List.append_nil_l (MkSeq?.l s)
let append_empty_r #a s = List.append_l_nil (MkSeq?.l s)
private
let rec init_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> Tot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux len k contents) 0 == contents k
else index (init_aux len k contents) i == index (init_aux len (k+1) contents) (i-1))
end
let init_index #_ len contents =
if len = 0 then () else init_index_aux len 0 contents
let init_index_ #_ len contents j = init_index len contents
private
let rec init_ghost_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux_ghost len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_ghost_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux_ghost len k contents) 0 == contents k
else index (init_aux_ghost len k contents) i == index (init_aux_ghost len (k+1) contents) (i-1))
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Prims.nat -> contents: (i: Prims.nat{i < len} -> Prims.GTot a)
-> FStar.Pervasives.Lemma
(ensures
forall (i: Prims.nat{i < len}).
FStar.Seq.Base.index (FStar.Seq.Base.init_ghost len contents) i == contents i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.init_ghost_index_aux",
"Prims.unit"
] | [] | false | false | true | false | false | let init_ghost_index #_ len contents =
| if len = 0 then () else init_ghost_index_aux len 0 contents | false |
CPS.DoubleLambdaLifting.fst | CPS.DoubleLambdaLifting.eval_cps1 | val eval_cps1 : (int -> Tot 'a) -> int -> int -> Tot 'a | val eval_cps1 : (int -> Tot 'a) -> int -> int -> Tot 'a | let eval_cps1 k r1 r2 = k (r1 + r2) | {
"file_name": "examples/termination/CPS.DoubleLambdaLifting.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(** With λ-lifting **)
module CPS.DoubleLambdaLifting
open CPS.Expr | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"CPS.Expr.fst.checked"
],
"interface_file": false,
"source_file": "CPS.DoubleLambdaLifting.fst"
} | [
{
"abbrev": false,
"full_module": "CPS.Expr",
"short_module": null
},
{
"abbrev": false,
"full_module": "CPS",
"short_module": null
},
{
"abbrev": false,
"full_module": "CPS",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: (_: Prims.int -> 'a) -> r1: Prims.int -> r2: Prims.int -> 'a | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Prims.op_Addition"
] | [] | false | false | false | true | false | let eval_cps1 k r1 r2 =
| k (r1 + r2) | false |
FStar.Seq.Base.fst | FStar.Seq.Base.init_index_aux | val init_index_aux (#a: Type) (len: nat) (k: nat{k < len}) (contents: (i: nat{i < len} -> Tot a))
: Lemma (requires True)
(ensures (forall (i: nat{i < len - k}). index (init_aux len k contents) i == contents (k + i))
)
(decreases (len - k)) | val init_index_aux (#a: Type) (len: nat) (k: nat{k < len}) (contents: (i: nat{i < len} -> Tot a))
: Lemma (requires True)
(ensures (forall (i: nat{i < len - k}). index (init_aux len k contents) i == contents (k + i))
)
(decreases (len - k)) | let rec init_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> Tot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux len k contents) 0 == contents k
else index (init_aux len k contents) i == index (init_aux len (k+1) contents) (i-1))
end | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 263,
"start_col": 0,
"start_line": 251
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *)
let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3)
let append_empty_l #a s = List.append_nil_l (MkSeq?.l s)
let append_empty_r #a s = List.append_l_nil (MkSeq?.l s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Prims.nat -> k: Prims.nat{k < len} -> contents: (i: Prims.nat{i < len} -> a)
-> FStar.Pervasives.Lemma
(ensures
forall (i: Prims.nat{i < len - k}).
FStar.Seq.Base.index (FStar.Seq.Base.init_aux len k contents) i == contents (k + i))
(decreases len - k) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"Prims._assert",
"Prims.l_Forall",
"Prims.op_Subtraction",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.init_aux",
"Prims.unit",
"FStar.Seq.Base.init_index_aux",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec init_index_aux
(#a: Type)
(len: nat)
(k: nat{k < len})
(contents: (i: nat{i < len} -> Tot a))
: Lemma (requires True)
(ensures (forall (i: nat{i < len - k}). index (init_aux len k contents) i == contents (k + i))
)
(decreases (len - k)) =
| if k + 1 = len
then ()
else
(init_index_aux #a len (k + 1) contents;
assert (forall (i: nat{i < len - k}).
if i = 0
then index (init_aux len k contents) 0 == contents k
else index (init_aux len k contents) i == index (init_aux len (k + 1) contents) (i - 1))) | false |
Steel.ST.GhostReference.fst | Steel.ST.GhostReference.ref | val ref (a:Type u#0)
: Type u#0 | val ref (a:Type u#0)
: Type u#0 | let ref (a:Type u#0)
: Type u#0
= R.ghost_ref a | {
"file_name": "lib/steel/Steel.ST.GhostReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 25,
"start_col": 0,
"start_line": 23
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.GhostReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.Reference | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.Reference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GhostReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Steel.Reference.ghost_ref"
] | [] | false | false | false | true | true | let ref (a: Type u#0) : Type u#0 =
| R.ghost_ref a | false |
FStar.Seq.Base.fst | FStar.Seq.Base.init_ghost_index_aux | val init_ghost_index_aux
(#a: Type)
(len: nat)
(k: nat{k < len})
(contents: (i: nat{i < len} -> GTot a))
: Lemma (requires True)
(ensures
(forall (i: nat{i < len - k}). index (init_aux_ghost len k contents) i == contents (k + i)))
(decreases (len - k)) | val init_ghost_index_aux
(#a: Type)
(len: nat)
(k: nat{k < len})
(contents: (i: nat{i < len} -> GTot a))
: Lemma (requires True)
(ensures
(forall (i: nat{i < len - k}). index (init_aux_ghost len k contents) i == contents (k + i)))
(decreases (len - k)) | let rec init_ghost_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux_ghost len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_ghost_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux_ghost len k contents) 0 == contents k
else index (init_aux_ghost len k contents) i == index (init_aux_ghost len (k+1) contents) (i-1))
end | {
"file_name": "ulib/FStar.Seq.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 283,
"start_col": 0,
"start_line": 271
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.
*)
(* A logical theory of sequences indexed by natural numbers in [0, n) *)
module FStar.Seq.Base
//#set-options "--initial_fuel 0 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1"
module List = FStar.List.Tot
type seq (a:Type u#a) :Type u#a =
| MkSeq: l:list a -> seq a
let length #_ s = List.length (MkSeq?.l s)
let seq_to_list #_ s =
match s with
| MkSeq l -> l
let seq_of_list #_ l = MkSeq l
let index #_ s i = List.index (MkSeq?.l s) i
let _cons (#a:Type) (x:a) (s:seq a) : Tot (seq a) = MkSeq (x::(MkSeq?.l s))
let hd (#a:Type) (s:seq a{length s > 0}) : Tot a = List.hd (MkSeq?.l s)
let tl (#a:Type) (s:seq a{length s > 0}) : Tot (seq a) = MkSeq (List.tl (MkSeq?.l s))
let rec create #_ len v = if len = 0 then MkSeq [] else _cons v (create (len - 1) v)
private let rec init_aux' (#a:Type) (len:nat) (k:nat{k < len}) (contents: (i:nat{i < len} -> Tot a))
: Tot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux' len (k+1) contents)
let init_aux = init_aux'
let init #_ len contents = if len = 0 then MkSeq [] else init_aux len 0 contents
private let rec init_aux_ghost' (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> GTot a))
: GTot (seq a)
(decreases (len - k))
= if k + 1 = len
then MkSeq [contents k]
else _cons (contents k) (init_aux_ghost' len (k+1) contents)
let init_aux_ghost = init_aux_ghost'
let init_ghost #_ len contents = if len = 0 then MkSeq [] else init_aux_ghost len 0 contents
let empty #_ = MkSeq []
let lemma_empty #_ _ = ()
private let rec upd' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Tot (seq a)
(decreases (length s))
= if n = 0 then _cons v (tl s) else _cons (hd s) (upd' (tl s) (n - 1) v)
let upd = upd'
let append #_ s1 s2 = MkSeq (List.append (MkSeq?.l s1) (MkSeq?.l s2))
private let rec slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Tot (seq a)
(decreases (length s))
= if i > 0 then slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then MkSeq []
else _cons (hd s) (slice' #a (tl s) i (j - 1))
let slice = slice'
let lemma_seq_of_seq_to_list #_ s = ()
let lemma_seq_to_seq_of_list #_ s = ()
let lemma_seq_of_list_cons #_ x l = ()
let lemma_seq_to_list_cons #_ x s = ()
let rec lemma_create_len #_ n i = if n = 0 then () else lemma_create_len (n - 1) i
let rec lemma_init_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> Tot a))
: Lemma (requires True)
(ensures (length (init_aux n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_aux_len' #a n (k+1) contents
let lemma_init_len #_ n contents = if n = 0 then () else lemma_init_aux_len' n 0 contents
let lemma_init_aux_len = lemma_init_aux_len'
private let rec lemma_init_ghost_aux_len' (#a:Type) (n:nat) (k:nat{k < n}) (contents:(i:nat{ i < n } -> GTot a))
: Lemma (requires True)
(ensures (length (init_aux_ghost n k contents) = n - k))
(decreases (n-k))
= if k + 1 = n then () else lemma_init_ghost_aux_len' #a n (k+1) contents
let lemma_init_ghost_len #_ n contents = if n = 0 then () else lemma_init_ghost_aux_len' n 0 contents
let lemma_init_ghost_aux_len = lemma_init_ghost_aux_len'
let rec lemma_len_upd #_ n v s = if n = 0 then () else lemma_len_upd (n - 1) v (tl s)
let lemma_len_append #_ s1 s2 = FStar.List.Tot.append_length (MkSeq?.l s1) (MkSeq?.l s2)
let rec lemma_len_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j && j <= length s})
: Lemma
(requires True)
(ensures (length (slice s i j) = j - i)) (decreases (length s))
= if i > 0 then lemma_len_slice' #a (tl s) (i - 1) (j - 1)
else if j = 0 then ()
else lemma_len_slice' #a (tl s) i (j - 1)
let lemma_len_slice = lemma_len_slice'
let rec lemma_index_create #_ n v i =
if n = 0 then ()
else if i = 0 then ()
else (lemma_create_len (n - 1) v; lemma_index_create (n - 1) v (i - 1))
let rec lemma_index_upd1' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a)
: Lemma
(requires True)
(ensures (index (upd s n v) n == v)) (decreases (length s))
= if n = 0
then ()
else begin
lemma_index_upd1' #a (tl s) (n - 1) v;
assert (index (upd (tl s) (n-1) v) (n-1) == v)
end
let lemma_index_upd1 = lemma_index_upd1'
let rec lemma_index_upd2' (#a:Type) (s:seq a) (n:nat{n < length s}) (v:a) (i:nat{i<>n /\ i < length s})
: Lemma
(requires True)
(ensures (index (upd s n v) i == index s i))
(decreases (length s))
= match (MkSeq?.l s) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else
if n = 0 then ()
else (lemma_len_upd (n - 1) v (MkSeq tl); lemma_index_upd2' #a (MkSeq tl) (n - 1) v (i - 1))
let lemma_index_upd2 = lemma_index_upd2'
let rec lemma_index_app1' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s1 i)) (decreases (length s1))
= match (MkSeq?.l s1) with
| [] -> ()
| hd::tl ->
if i = 0 then ()
else (lemma_len_append (MkSeq tl) s2; lemma_index_app1' #a (MkSeq tl) s2 (i - 1))
let lemma_index_app1 = lemma_index_app1'
let rec lemma_index_app2' (#a:Type) (s1:seq a) (s2:seq a) (i:nat{i < length s1 + length s2 /\ length s1 <= i})
: Lemma
(requires True)
(ensures (index (append s1 s2) i == index s2 (i - length s1))) (decreases (length s1))
= match s1.l with
| [] -> ()
| hd::tl -> lemma_index_app2' #a (MkSeq tl) s2 (i - 1)
let lemma_index_app2 = lemma_index_app2'
let rec lemma_index_slice0' (#a:Type) (s:seq a) (j:nat{j <= length s}) (k : nat{k < j})
: Lemma
(requires True)
(ensures (index (slice s 0 j) k == index s k)) (decreases (length s))
= if k = 0
then ()
else lemma_index_slice0' (tl s) (j-1) (k-1)
#push-options "--fuel 1 --ifuel 0"
let rec lemma_index_slice' (#a:Type) (s:seq a) (i:nat) (j:nat{i <= j /\ j <= length s}) (k:nat{k < j - i})
: Lemma
(requires True)
(ensures (index (slice s i j) k == index s (k + i))) (decreases (length s))
= if i > 0
then (
lemma_index_slice' #a (tl s) (i - 1) (j - 1) k;
assert (index (slice (tl s) (i - 1) (j - 1)) k == index (tl s) (k + (i - 1)));
assert (index (slice (tl s) (i - 1) (j - 1)) k == index s (k + i));
assert (index (slice s i j) k == index s (k + i))
)
else (
assert (j > 0);
lemma_index_slice0' #a s j k
)
#pop-options
let lemma_index_slice = lemma_index_slice'
let hasEq_lemma _ = ()
let equal #a s1 s2 =
(length s1 = length s2
/\ (forall (i:nat{i < length s1}).{:pattern (index s1 i); (index s2 i)} (index s1 i == index s2 i)))
let rec eq_i' (#a:eqtype) (s1:seq a) (s2:seq a{length s1 == length s2}) (i:nat{i <= length s1})
: Tot (r:bool{r <==> (forall j. (j >= i /\ j < length s1) ==> (index s1 j = index s2 j))})
(decreases (length s1 - i))
= if i = length s1 then true
else
if index s1 i = index s2 i then eq_i' s1 s2 (i + 1)
else false
let eq_i = eq_i'
let eq #_ s1 s2 = if length s1 = length s2 then eq_i s1 s2 0 else false
let lemma_eq_intro #_ s1 s2 = ()
let lemma_eq_refl #_ s1 s2 = ()
let lemma_eq_elim #_ s1 s2 =
assert ( length s1 == List.length (MkSeq?.l s1) );
assert ( length s2 == List.length (MkSeq?.l s2) );
assert ( forall (i: nat) . i < length s1 ==> index s1 i == List.index (MkSeq?.l s1) i);
assert ( forall (i: nat) . i < length s1 ==> index s2 i == List.index (MkSeq?.l s2) i);
List.index_extensionality (MkSeq?.l s1) (MkSeq?.l s2)
(* Properties of [append] *)
let append_assoc #a s1 s2 s3 = List.append_assoc (MkSeq?.l s1) (MkSeq?.l s2) (MkSeq?.l s3)
let append_empty_l #a s = List.append_nil_l (MkSeq?.l s)
let append_empty_r #a s = List.append_l_nil (MkSeq?.l s)
private
let rec init_index_aux (#a:Type) (len:nat) (k:nat{k < len}) (contents:(i:nat { i < len } -> Tot a))
: Lemma (requires True)
(ensures (forall (i:nat{i < len - k}).index (init_aux len k contents) i == contents (k + i)))
(decreases (len - k))
=
if k + 1 = len
then ()
else begin
init_index_aux #a len (k+1) contents ;
assert (forall (i:nat{i < len - k}).
if i = 0 then index (init_aux len k contents) 0 == contents k
else index (init_aux len k contents) i == index (init_aux len (k+1) contents) (i-1))
end
let init_index #_ len contents =
if len = 0 then () else init_index_aux len 0 contents
let init_index_ #_ len contents j = init_index len contents | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Seq.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Prims.nat -> k: Prims.nat{k < len} -> contents: (i: Prims.nat{i < len} -> Prims.GTot a)
-> FStar.Pervasives.Lemma
(ensures
forall (i: Prims.nat{i < len - k}).
FStar.Seq.Base.index (FStar.Seq.Base.init_aux_ghost len k contents) i == contents (k + i))
(decreases len - k) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.bool",
"Prims._assert",
"Prims.l_Forall",
"Prims.op_Subtraction",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.init_aux_ghost",
"Prims.unit",
"FStar.Seq.Base.init_ghost_index_aux",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec init_ghost_index_aux
(#a: Type)
(len: nat)
(k: nat{k < len})
(contents: (i: nat{i < len} -> GTot a))
: Lemma (requires True)
(ensures
(forall (i: nat{i < len - k}). index (init_aux_ghost len k contents) i == contents (k + i)))
(decreases (len - k)) =
| if k + 1 = len
then ()
else
(init_ghost_index_aux #a len (k + 1) contents;
assert (forall (i: nat{i < len - k}).
if i = 0
then index (init_aux_ghost len k contents) 0 == contents k
else
index (init_aux_ghost len k contents) i ==
index (init_aux_ghost len (k + 1) contents) (i - 1))) | false |
Steel.ST.GhostReference.fst | Steel.ST.GhostReference.dummy_ref | val dummy_ref (a: Type) : Tot (ref a) | val dummy_ref (a: Type) : Tot (ref a) | let dummy_ref a = R.dummy_ghost_ref a | {
"file_name": "lib/steel/Steel.ST.GhostReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 27,
"start_col": 0,
"start_line": 27
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.GhostReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.Reference
[@@ erasable]
let ref (a:Type u#0)
: Type u#0
= R.ghost_ref a | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.Reference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GhostReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Steel.ST.GhostReference.ref a | Prims.Tot | [
"total"
] | [] | [
"Steel.Reference.dummy_ghost_ref",
"Steel.ST.GhostReference.ref"
] | [] | false | false | false | true | false | let dummy_ref a =
| R.dummy_ghost_ref a | false |
Steel.ST.GhostReference.fst | Steel.ST.GhostReference.pts_to | val pts_to (#a:_)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop | val pts_to (#a:_)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop | let pts_to (#a:_)
(r:ref a)
(p:perm)
([@@@smt_fallback] v:a)
: vprop
= R.ghost_pts_to r p v | {
"file_name": "lib/steel/Steel.ST.GhostReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 34,
"start_col": 0,
"start_line": 29
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.GhostReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.Reference
[@@ erasable]
let ref (a:Type u#0)
: Type u#0
= R.ghost_ref a
let dummy_ref a = R.dummy_ghost_ref a | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.Reference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GhostReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.ST.GhostReference.ref a -> p: Steel.FractionalPermission.perm -> v: a
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GhostReference.ref",
"Steel.FractionalPermission.perm",
"Steel.Reference.ghost_pts_to",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | true | false | let pts_to (#a: _) (r: ref a) (p: perm) ([@@@ smt_fallback]v: a) : vprop =
| R.ghost_pts_to r p v | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.has_elements | val has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a) : prop | val has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a) : prop | let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 43,
"start_col": 0,
"start_line": 42
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: a ^-> Prims.bool -> xs: Prims.list a -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FunctionalExtensionality.op_Hat_Subtraction_Greater",
"Prims.bool",
"Prims.list",
"Prims.l_Forall",
"Prims.eq2",
"FStar.List.Tot.Base.mem",
"Prims.prop"
] | [] | false | false | false | false | true | let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a) : prop =
| forall x. f x == x `FLT.mem` xs | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.mem | val mem (#a: eqtype) (x: a) (s: set a)
: bool | val mem (#a: eqtype) (x: a) (s: set a)
: bool | let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 51,
"start_col": 0,
"start_line": 50
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`: | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> s: FStar.FiniteSet.Base.set a -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"Prims.bool"
] | [] | false | false | false | false | false | let mem (#a: eqtype) (x: a) (s: set a) : bool =
| s x | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.cardinality | val cardinality (#a: eqtype) (s: set a)
: GTot nat | val cardinality (#a: eqtype) (s: set a)
: GTot nat | let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 68,
"start_col": 0,
"start_line": 67
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.FiniteSet.Base.set a -> Prims.GTot Prims.nat | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.List.Tot.Base.length",
"FStar.FiniteSet.Base.set_as_list",
"Prims.nat"
] | [] | false | false | false | false | false | let cardinality (#a: eqtype) (s: set a) : GTot nat =
| FLT.length (set_as_list s) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.remove_repeats | val remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a {list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) | val remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a {list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) | let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl' | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 87,
"end_line": 61,
"start_col": 0,
"start_line": 57
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | xs: Prims.list a
-> ys:
Prims.list a
{ FStar.FiniteSet.Base.list_nonrepeating ys /\
(forall (y: a). FStar.List.Tot.Base.mem y ys <==> FStar.List.Tot.Base.mem y xs) } | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.Nil",
"FStar.List.Tot.Base.mem",
"Prims.bool",
"Prims.Cons",
"Prims.l_and",
"Prims.b2t",
"FStar.FiniteSet.Base.list_nonrepeating",
"Prims.l_Forall",
"Prims.l_iff",
"FStar.FiniteSet.Base.remove_repeats"
] | [
"recursion"
] | false | false | false | false | false | let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a {list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
| match xs with
| [] -> []
| hd :: tl ->
let tl' = remove_repeats tl in
if FLT.mem hd tl then tl' else hd :: tl' | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.singleton | val singleton (#a: eqtype) (x: a)
: set a | val singleton (#a: eqtype) (x: a)
: set a | let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 93,
"start_col": 0,
"start_line": 92
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> FStar.FiniteSet.Base.set a | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.insert",
"FStar.FiniteSet.Base.emptyset",
"FStar.FiniteSet.Base.set"
] | [] | false | false | false | false | false | let singleton (#a: eqtype) (x: a) : set a =
| insert x emptyset | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.set_as_list | val set_as_list (#a: eqtype) (s: set a)
: GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) | val set_as_list (#a: eqtype) (s: set a)
: GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) | let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s)) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 129,
"end_line": 64,
"start_col": 0,
"start_line": 63
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.FiniteSet.Base.set a
-> Prims.GTot
(xs:
Prims.list a
{ FStar.FiniteSet.Base.list_nonrepeating xs /\
(forall (x: a). FStar.List.Tot.Base.mem x xs = FStar.FiniteSet.Base.mem x s) }) | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FiniteSet.Base.remove_repeats",
"FStar.IndefiniteDescription.indefinite_description_ghost",
"Prims.list",
"Prims.l_Forall",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"FStar.List.Tot.Base.mem",
"FStar.FiniteSet.Base.mem",
"Prims.prop",
"Prims.l_and",
"FStar.FiniteSet.Base.list_nonrepeating"
] | [] | false | false | false | false | false | let set_as_list (#a: eqtype) (s: set a)
: GTot (xs: list a {list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
| remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a)
(fun xs -> forall x. FLT.mem x xs = mem x s)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.emptyset | val emptyset (#a: eqtype)
: set a | val emptyset (#a: eqtype)
: set a | let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) [] | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 79,
"start_col": 0,
"start_line": 79
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`: | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.FiniteSet.Base.set a | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.intro_set",
"FStar.FunctionalExtensionality.on_dom",
"Prims.bool",
"FStar.Ghost.hide",
"Prims.list",
"Prims.Nil",
"FStar.FiniteSet.Base.set"
] | [] | false | false | false | false | false | let emptyset (#a: eqtype) : set a =
| intro_set (on_dom a (fun _ -> false)) [] | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.intro_set | val intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a) (requires f `has_elements` xs) (ensures fun _ -> True) | val intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a) (requires f `has_elements` xs) (ensures fun _ -> True) | let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 75,
"start_col": 0,
"start_line": 70
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: a ^-> Prims.bool -> xs: FStar.Ghost.erased (Prims.list a)
-> Prims.Pure (FStar.FiniteSet.Base.set a) | Prims.Pure | [] | [] | [
"Prims.eqtype",
"FStar.FunctionalExtensionality.op_Hat_Subtraction_Greater",
"Prims.bool",
"FStar.Ghost.erased",
"Prims.list",
"Prims.unit",
"FStar.Classical.exists_intro",
"FStar.FiniteSet.Base.has_elements",
"FStar.Ghost.reveal",
"FStar.FiniteSet.Base.set",
"Prims.l_True"
] | [] | false | false | false | false | false | let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a) (requires f `has_elements` xs) (ensures fun _ -> True) =
| Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.subset | val subset (#a: eqtype) (s1: set a) (s2: set a)
: Type0 | val subset (#a: eqtype) (s1: set a) (s2: set a)
: Type0 | let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 138,
"start_col": 0,
"start_line": 137
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool"
] | [] | false | false | false | false | true | let subset (#a: eqtype) (s1 s2: set a) : Type0 =
| forall x. (s1 x = true) ==> (s2 x = true) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.union_lists | val union_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) | val union_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) | let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 102,
"start_col": 0,
"start_line": 99
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | xs: Prims.list a -> ys: Prims.list a
-> zs:
Prims.list a
{ forall (z: a).
FStar.List.Tot.Base.mem z zs <==>
FStar.List.Tot.Base.mem z xs \/ FStar.List.Tot.Base.mem z ys } | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.Cons",
"FStar.FiniteSet.Base.union_lists",
"Prims.l_Forall",
"Prims.l_iff",
"Prims.b2t",
"FStar.List.Tot.Base.mem",
"Prims.l_or"
] | [
"recursion"
] | false | false | false | false | false | let rec union_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
| match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.equal | val equal (#a: eqtype) (s1: set a) (s2: set a)
: Type0 | val equal (#a: eqtype) (s1: set a) (s2: set a)
: Type0 | let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2 | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 145,
"start_col": 0,
"start_line": 144
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FunctionalExtensionality.feq",
"Prims.bool"
] | [] | false | false | false | false | true | let equal (#a: eqtype) (s1 s2: set a) : Type0 =
| feq s1 s2 | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.union | val union (#a: eqtype) (s1: set a) (s2: set a)
: (set a) | val union (#a: eqtype) (s1: set a) (s2: set a)
: (set a) | let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2)) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 94,
"end_line": 105,
"start_col": 0,
"start_line": 104
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> FStar.FiniteSet.Base.set a | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FiniteSet.Base.intro_set",
"FStar.FunctionalExtensionality.on_dom",
"Prims.bool",
"Prims.op_BarBar",
"FStar.Ghost.hide",
"Prims.list",
"FStar.FiniteSet.Base.union_lists",
"FStar.FiniteSet.Base.set_as_list"
] | [] | false | false | false | false | false | let union (#a: eqtype) (s1 s2: set a) : (set a) =
| intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.disjoint | val disjoint (#a: eqtype) (s1: set a) (s2: set a)
: Type0 | val disjoint (#a: eqtype) (s1: set a) (s2: set a)
: Type0 | let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 152,
"start_col": 0,
"start_line": 151
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"Prims.l_Forall",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_AmpAmp"
] | [] | false | false | false | false | true | let disjoint (#a: eqtype) (s1 s2: set a) : Type0 =
| forall x. not (s1 x && s2 x) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.insert | val insert (#a: eqtype) (x: a) (s: set a)
: set a | val insert (#a: eqtype) (x: a) (s: set a)
: set a | let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 86,
"start_col": 0,
"start_line": 85
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> s: FStar.FiniteSet.Base.set a -> FStar.FiniteSet.Base.set a | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FiniteSet.Base.intro_set",
"FStar.FunctionalExtensionality.on_dom",
"Prims.bool",
"Prims.op_BarBar",
"Prims.op_Equality",
"FStar.Ghost.hide",
"Prims.list",
"Prims.Cons",
"FStar.FiniteSet.Base.set_as_list"
] | [] | false | false | false | false | false | let insert (#a: eqtype) (x: a) (s: set a) : set a =
| intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.intersect_lists | val intersect_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) | val intersect_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) | let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs' | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 91,
"end_line": 115,
"start_col": 0,
"start_line": 111
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | xs: Prims.list a -> ys: Prims.list a
-> zs:
Prims.list a
{ forall (z: a).
FStar.List.Tot.Base.mem z zs <==>
FStar.List.Tot.Base.mem z xs /\ FStar.List.Tot.Base.mem z ys } | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.Nil",
"FStar.List.Tot.Base.mem",
"Prims.Cons",
"Prims.bool",
"Prims.l_Forall",
"Prims.l_iff",
"Prims.b2t",
"Prims.l_and",
"FStar.FiniteSet.Base.intersect_lists"
] | [
"recursion"
] | false | false | false | false | false | let rec intersect_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
| match xs with
| [] -> []
| hd :: tl ->
let zs' = intersect_lists tl ys in
if FLT.mem hd ys then hd :: zs' else zs' | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.intersection | val intersection (#a: eqtype) (s1: set a) (s2: set a)
: set a | val intersection (#a: eqtype) (s1: set a) (s2: set a)
: set a | let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2)) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 98,
"end_line": 118,
"start_col": 0,
"start_line": 117
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> FStar.FiniteSet.Base.set a | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FiniteSet.Base.intro_set",
"FStar.FunctionalExtensionality.on_dom",
"Prims.bool",
"Prims.op_AmpAmp",
"FStar.Ghost.hide",
"Prims.list",
"FStar.FiniteSet.Base.intersect_lists",
"FStar.FiniteSet.Base.set_as_list"
] | [] | false | false | false | false | false | let intersection (#a: eqtype) (s1 s2: set a) : set a =
| intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.difference_lists | val difference_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) | val difference_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) | let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs' | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 92,
"end_line": 128,
"start_col": 0,
"start_line": 124
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | xs: Prims.list a -> ys: Prims.list a
-> zs:
Prims.list a
{ forall (z: a).
FStar.List.Tot.Base.mem z zs <==>
FStar.List.Tot.Base.mem z xs /\ ~(FStar.List.Tot.Base.mem z ys) } | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.Nil",
"FStar.List.Tot.Base.mem",
"Prims.bool",
"Prims.Cons",
"Prims.l_Forall",
"Prims.l_iff",
"Prims.b2t",
"Prims.l_and",
"Prims.l_not",
"FStar.FiniteSet.Base.difference_lists"
] | [
"recursion"
] | false | false | false | false | false | let rec difference_lists (#a: eqtype) (xs ys: list a)
: (zs: list a {forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
| match xs with
| [] -> []
| hd :: tl ->
let zs' = difference_lists tl ys in
if FLT.mem hd ys then zs' else hd :: zs' | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.difference | val difference (#a: eqtype) (s1: set a) (s2: set a)
: set a | val difference (#a: eqtype) (s1: set a) (s2: set a)
: set a | let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2)) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 105,
"end_line": 131,
"start_col": 0,
"start_line": 130
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> FStar.FiniteSet.Base.set a | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FiniteSet.Base.intro_set",
"FStar.FunctionalExtensionality.on_dom",
"Prims.bool",
"Prims.op_AmpAmp",
"Prims.op_Negation",
"FStar.Ghost.hide",
"Prims.list",
"FStar.FiniteSet.Base.difference_lists",
"FStar.FiniteSet.Base.set_as_list"
] | [] | false | false | false | false | false | let difference (#a: eqtype) (s1 s2: set a) : set a =
| intro_set (on_dom a (fun x -> s1 x && not (s2 x)))
(difference_lists (set_as_list s1) (set_as_list s2)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.choose | val choose (#a: eqtype) (s: set a{exists x. mem x s})
: GTot (x: a{mem x s}) | val choose (#a: eqtype) (s: set a{exists x. mem x s})
: GTot (x: a{mem x s}) | let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 159,
"start_col": 0,
"start_line": 158
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s; | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.FiniteSet.Base.set a {exists (x: a). FStar.FiniteSet.Base.mem x s}
-> Prims.GTot (x: a{FStar.FiniteSet.Base.mem x s}) | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"Prims.l_Exists",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"Prims.__proj__Cons__item__hd",
"FStar.FiniteSet.Base.set_as_list"
] | [] | false | false | false | false | false | let choose (#a: eqtype) (s: set a {exists x. mem x s}) : GTot (x: a{mem x s}) =
| Cons?.hd (set_as_list s) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.singleton_cardinality_helper | val singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) | val singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) | let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 198,
"start_col": 0,
"start_line": 191
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: a -> xs: Prims.list a
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.mem r xs /\ (forall (x: a). FStar.List.Tot.Base.mem x xs <==> x = r))
(ensures FStar.FiniteSet.Base.remove_repeats xs == [r]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"FStar.FiniteSet.Base.singleton_cardinality_helper",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.__proj__Cons__item__hd",
"Prims.l_and",
"FStar.List.Tot.Base.mem",
"Prims.l_Forall",
"Prims.l_iff",
"Prims.squash",
"Prims.eq2",
"FStar.FiniteSet.Base.remove_repeats",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
| match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.length_zero_lemma | val length_zero_lemma: Prims.unit -> Lemma (length_zero_fact) | val length_zero_lemma: Prims.unit -> Lemma (length_zero_fact) | let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ()) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 181,
"start_col": 0,
"start_line": 169
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.length_zero_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_and",
"Prims.l_iff",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.FiniteSet.Base.cardinality",
"Prims.eq2",
"FStar.FiniteSet.Base.emptyset",
"Prims.op_disEquality",
"Prims.l_Exists",
"FStar.FiniteSet.Base.mem",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"FStar.Classical.Sugar.exists_intro",
"Prims.__proj__Cons__item__hd",
"FStar.FiniteSet.Base.set_as_list",
"Prims._assert",
"Prims.list",
"Prims.Nil",
"FStar.FunctionalExtensionality.feq",
"Prims.bool",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"Prims.l_True",
"FStar.FiniteSet.Base.length_zero_fact",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let length_zero_lemma () : Lemma (length_zero_fact) =
| introduce forall (a: eqtype) (s: set a) . (cardinality s = 0 <==> s == emptyset) /\
(cardinality s <> 0 <==> (exists x. mem x s))
with (reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x.mem x s
with (Cons?.hd (set_as_list s))
and ()) | false |
Steel.ST.GhostReference.fst | Steel.ST.GhostReference.pts_to_perm | val pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ref a)
: STGhost unit u
(pts_to r p v)
(fun _ -> pts_to r p v)
True
(fun _ -> p `lesser_equal_perm` full_perm) | val pts_to_perm (#a: _) (#u: _) (#p: _) (#v: _) (r: ref a)
: STGhost unit u
(pts_to r p v)
(fun _ -> pts_to r p v)
True
(fun _ -> p `lesser_equal_perm` full_perm) | let pts_to_perm r = coerce_ghost (fun _ -> R.ghost_pts_to_perm r) | {
"file_name": "lib/steel/Steel.ST.GhostReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 65,
"end_line": 49,
"start_col": 0,
"start_line": 49
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.GhostReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.Reference
[@@ erasable]
let ref (a:Type u#0)
: Type u#0
= R.ghost_ref a
let dummy_ref a = R.dummy_ghost_ref a
let pts_to (#a:_)
(r:ref a)
(p:perm)
([@@@smt_fallback] v:a)
: vprop
= R.ghost_pts_to r p v
let pts_to_injective_eq (#a:_)
(#u:_)
(#p #q:_)
(#v0 #v1:a)
(r:ref a)
: STGhost unit u
(pts_to r p v0 `star` pts_to r q v1)
(fun _ -> pts_to r p v0 `star` pts_to r q v0)
(requires True)
(ensures fun _ -> v0 == v1)
= coerce_ghost
(fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1)) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.Reference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GhostReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.ST.GhostReference.ref a -> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.ST.GhostReference.ref",
"Steel.ST.Coercions.coerce_ghost",
"Prims.unit",
"Steel.Reference.ghost_pts_to",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Prims.b2t",
"Steel.FractionalPermission.lesser_equal_perm",
"Steel.FractionalPermission.full_perm",
"Steel.Reference.ghost_pts_to_perm"
] | [] | false | true | false | false | false | let pts_to_perm r =
| coerce_ghost (fun _ -> R.ghost_pts_to_perm r) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.insert_member_cardinality_lemma | val insert_member_cardinality_lemma: Prims.unit -> Lemma (insert_member_cardinality_fact) | val insert_member_cardinality_lemma: Prims.unit -> Lemma (insert_member_cardinality_fact) | let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 242,
"start_col": 0,
"start_line": 234
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.insert_member_cardinality_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_imp",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"Prims.op_Equality",
"Prims.nat",
"FStar.FiniteSet.Base.cardinality",
"FStar.FiniteSet.Base.insert",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"FStar.FiniteSet.Base.nonrepeating_lists_with_same_elements_have_same_length",
"FStar.FiniteSet.Base.set_as_list",
"FStar.Pervasives.reveal_opaque",
"Prims.l_True",
"FStar.FiniteSet.Base.insert_member_cardinality_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact) =
| introduce forall (a: eqtype) (s: set a) (x: a) . mem x s ==>
cardinality (insert x s) = cardinality s
with introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.nonrepeating_lists_with_same_elements_have_same_length | val nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1 s2: list a)
: Lemma
(requires
list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) | val nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1 s2: list a)
: Lemma
(requires
list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) | let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 111,
"end_line": 232,
"start_col": 0,
"start_line": 227
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: Prims.list a -> s2: Prims.list a
-> FStar.Pervasives.Lemma
(requires
FStar.FiniteSet.Base.list_nonrepeating s1 /\ FStar.FiniteSet.Base.list_nonrepeating s2 /\
(forall (x: a). FStar.List.Tot.Base.mem x s1 <==> FStar.List.Tot.Base.mem x s2))
(ensures FStar.List.Tot.Base.length s1 = FStar.List.Tot.Base.length s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"FStar.FiniteSet.Base.nonrepeating_lists_with_same_elements_have_same_length",
"FStar.FiniteSet.Base.remove_from_nonrepeating_list",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"FStar.FiniteSet.Base.list_nonrepeating",
"Prims.l_Forall",
"Prims.l_iff",
"FStar.List.Tot.Base.mem",
"Prims.squash",
"Prims.op_Equality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1 s2: list a)
: Lemma
(requires
list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
| match s1 with
| [] -> ()
| hd :: tl ->
nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.remove_from_nonrepeating_list | val remove_from_nonrepeating_list
(#a: eqtype)
(x: a)
(xs: list a {FLT.mem x xs /\ list_nonrepeating xs})
: (xs':
list a
{ list_nonrepeating xs' /\ FLT.length xs' = FLT.length xs - 1 /\
(forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x) }) | val remove_from_nonrepeating_list
(#a: eqtype)
(x: a)
(xs: list a {FLT.mem x xs /\ list_nonrepeating xs})
: (xs':
list a
{ list_nonrepeating xs' /\ FLT.length xs' = FLT.length xs - 1 /\
(forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x) }) | let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 81,
"end_line": 225,
"start_col": 0,
"start_line": 220
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> xs: Prims.list a {FStar.List.Tot.Base.mem x xs /\ FStar.FiniteSet.Base.list_nonrepeating xs}
-> xs':
Prims.list a
{ FStar.FiniteSet.Base.list_nonrepeating xs' /\
FStar.List.Tot.Base.length xs' = FStar.List.Tot.Base.length xs - 1 /\
(forall (y: a). FStar.List.Tot.Base.mem y xs' <==> FStar.List.Tot.Base.mem y xs /\ y <> x) } | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.l_and",
"Prims.b2t",
"FStar.List.Tot.Base.mem",
"FStar.FiniteSet.Base.list_nonrepeating",
"Prims.op_Equality",
"Prims.bool",
"Prims.Cons",
"FStar.FiniteSet.Base.remove_from_nonrepeating_list",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.op_Subtraction",
"Prims.l_Forall",
"Prims.l_iff",
"Prims.op_disEquality"
] | [
"recursion"
] | false | false | false | false | false | let rec remove_from_nonrepeating_list
(#a: eqtype)
(x: a)
(xs: list a {FLT.mem x xs /\ list_nonrepeating xs})
: (xs':
list a
{ list_nonrepeating xs' /\ FLT.length xs' = FLT.length xs - 1 /\
(forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x) }) =
| match xs with | hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl) | false |
Spec.Frodo.Encode.fst | Spec.Frodo.Encode.dc | val dc:
logq:size_pos{logq <= 16}
-> b:size_pos{b < logq}
-> c:uint16
-> Pure uint16
(requires True)
(ensures fun r ->
v r < pow2 b /\ v r = (v c + pow2 (logq - b - 1)) / pow2 (logq - b) % pow2 b) | val dc:
logq:size_pos{logq <= 16}
-> b:size_pos{b < logq}
-> c:uint16
-> Pure uint16
(requires True)
(ensures fun r ->
v r < pow2 b /\ v r = (v c + pow2 (logq - b - 1)) / pow2 (logq - b) % pow2 b) | let dc logq b c =
let res1 = (c +. (u16 1 <<. size (logq - b - 1))) >>. size (logq - b) in
Math.Lemmas.pow2_lt_compat 16 (16 - logq + b);
calc (==) {
v res1;
(==) { }
(((v c + pow2 (logq - b - 1) % modulus U16) % modulus U16) / pow2 (logq - b)) % modulus U16;
(==) { Math.Lemmas.lemma_mod_plus_distr_r (v c) (pow2 (logq - b - 1)) (modulus U16) }
(((v c + pow2 (logq - b - 1)) % modulus U16) / pow2 (logq - b)) % modulus U16;
(==) { Math.Lemmas.pow2_modulo_division_lemma_1 (v c + pow2 (logq - b - 1)) (logq - b) 16 }
(((v c + pow2 (logq - b - 1)) / pow2 (logq - b)) % pow2 (16 - logq + b)) % modulus U16;
(==) { Math.Lemmas.pow2_modulo_modulo_lemma_2 ((v c + pow2 (logq - b - 1)) / pow2 (logq - b)) 16 (16 - logq + b) }
((v c + pow2 (logq - b - 1)) / pow2 (logq - b)) % pow2 (16 - logq + b);
};
let res = res1 &. ((u16 1 <<. size b) -. u16 1) in
Math.Lemmas.pow2_lt_compat 16 b;
calc (==) {
v res;
(==) { modulo_pow2_u16 res1 b }
v res1 % pow2 b;
(==) { Math.Lemmas.pow2_modulo_modulo_lemma_1 ((v c + pow2 (logq - b - 1)) / pow2 (logq - b)) b (16 - logq + b) }
((v c + pow2 (logq - b - 1)) / pow2 (logq - b)) % pow2 b;
};
res | {
"file_name": "specs/frodo/Spec.Frodo.Encode.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 81,
"start_col": 0,
"start_line": 55
} | module Spec.Frodo.Encode
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Lemmas
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** The simplified version of the encode and decode functions when n = params_nbar = 8 *)
val ec:
logq:size_pos{logq <= 16}
-> b:size_pos{b <= logq}
-> k:uint16{v k < pow2 b}
-> Pure uint16
(requires True)
(ensures fun r ->
v r < pow2 logq /\ v r == v k * pow2 (logq - b))
let ec logq b k =
let res = k <<. size (logq - b) in
assert (v res = v k * pow2 (logq - b) % modulus U16);
calc (<) {
v k * pow2 (logq - b);
(<) { Math.Lemmas.lemma_mult_lt_right (pow2 (logq - b)) (v k) (pow2 b) }
pow2 b * pow2 (logq - b);
(==) { Math.Lemmas.pow2_plus b (logq - b) }
pow2 logq;
};
Math.Lemmas.pow2_le_compat 16 logq;
Math.Lemmas.small_modulo_lemma_2 (v k * pow2 (logq - b)) (modulus U16);
assert (v res = v k * pow2 (logq - b));
res
val dc:
logq:size_pos{logq <= 16}
-> b:size_pos{b < logq}
-> c:uint16
-> Pure uint16
(requires True)
(ensures fun r ->
v r < pow2 b /\ v r = (v c + pow2 (logq - b - 1)) / pow2 (logq - b) % pow2 b) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.Encode.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
logq: Lib.IntTypes.size_pos{logq <= 16} ->
b: Lib.IntTypes.size_pos{b < logq} ->
c: Lib.IntTypes.uint16
-> Prims.Pure Lib.IntTypes.uint16 | Prims.Pure | [] | [] | [
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Lib.IntTypes.uint16",
"Prims.unit",
"FStar.Calc.calc_finish",
"Lib.IntTypes.range_t",
"Lib.IntTypes.U16",
"Prims.eq2",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.op_Addition",
"Prims.pow2",
"Prims.op_Subtraction",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Spec.Frodo.Lemmas.modulo_pow2_u16",
"Prims.squash",
"FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1",
"FStar.Math.Lemmas.pow2_lt_compat",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.u16",
"Lib.IntTypes.size",
"Lib.IntTypes.modulus",
"FStar.Math.Lemmas.lemma_mod_plus_distr_r",
"FStar.Math.Lemmas.pow2_modulo_division_lemma_1",
"FStar.Math.Lemmas.pow2_modulo_modulo_lemma_2",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Lib.IntTypes.op_Plus_Dot"
] | [] | false | false | false | false | false | let dc logq b c =
| let res1 = (c +. (u16 1 <<. size (logq - b - 1))) >>. size (logq - b) in
Math.Lemmas.pow2_lt_compat 16 (16 - logq + b);
calc ( == ) {
v res1;
( == ) { () }
(((v c + pow2 (logq - b - 1) % modulus U16) % modulus U16) / pow2 (logq - b)) % modulus U16;
( == ) { Math.Lemmas.lemma_mod_plus_distr_r (v c) (pow2 (logq - b - 1)) (modulus U16) }
(((v c + pow2 (logq - b - 1)) % modulus U16) / pow2 (logq - b)) % modulus U16;
( == ) { Math.Lemmas.pow2_modulo_division_lemma_1 (v c + pow2 (logq - b - 1)) (logq - b) 16 }
(((v c + pow2 (logq - b - 1)) / pow2 (logq - b)) % pow2 (16 - logq + b)) % modulus U16;
( == ) { Math.Lemmas.pow2_modulo_modulo_lemma_2 ((v c + pow2 (logq - b - 1)) / pow2 (logq - b))
16
(16 - logq + b) }
((v c + pow2 (logq - b - 1)) / pow2 (logq - b)) % pow2 (16 - logq + b);
};
let res = res1 &. ((u16 1 <<. size b) -. u16 1) in
Math.Lemmas.pow2_lt_compat 16 b;
calc ( == ) {
v res;
( == ) { modulo_pow2_u16 res1 b }
v res1 % pow2 b;
( == ) { Math.Lemmas.pow2_modulo_modulo_lemma_1 ((v c + pow2 (logq - b - 1)) / pow2 (logq - b))
b
(16 - logq + b) }
((v c + pow2 (logq - b - 1)) / pow2 (logq - b)) % pow2 b;
};
res | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.union_of_disjoint_sets_cardinality_lemma | val union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1 s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) | val union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1 s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) | let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2)) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 113,
"end_line": 315,
"start_col": 0,
"start_line": 311
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a
-> FStar.Pervasives.Lemma (requires FStar.FiniteSet.Base.disjoint s1 s2)
(ensures
FStar.FiniteSet.Base.cardinality (FStar.FiniteSet.Base.union s1 s2) =
FStar.FiniteSet.Base.cardinality s1 + FStar.FiniteSet.Base.cardinality s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FiniteSet.Base.union_of_disjoint_nonrepeating_lists_length_lemma",
"FStar.FiniteSet.Base.set_as_list",
"FStar.FiniteSet.Base.union",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"FStar.FiniteSet.Base.cardinality",
"FStar.FiniteSet.Base.disjoint",
"Prims.squash",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1 s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
| reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1)
(set_as_list s2)
(set_as_list (union s1 s2)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.union_of_three_disjoint_sets_cardinality_lemma | val union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1 s2 s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures
cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) | val union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1 s2 s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures
cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) | let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3 | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 321,
"start_col": 0,
"start_line": 317
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> s3: FStar.FiniteSet.Base.set a
-> FStar.Pervasives.Lemma
(requires
FStar.FiniteSet.Base.disjoint s1 s2 /\ FStar.FiniteSet.Base.disjoint s2 s3 /\
FStar.FiniteSet.Base.disjoint s1 s3)
(ensures
FStar.FiniteSet.Base.cardinality (FStar.FiniteSet.Base.union (FStar.FiniteSet.Base.union s1
s2)
s3) =
FStar.FiniteSet.Base.cardinality s1 + FStar.FiniteSet.Base.cardinality s2 +
FStar.FiniteSet.Base.cardinality s3) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.FiniteSet.Base.union_of_disjoint_sets_cardinality_lemma",
"FStar.FiniteSet.Base.union",
"Prims.unit",
"Prims.l_and",
"FStar.FiniteSet.Base.disjoint",
"Prims.squash",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.FiniteSet.Base.cardinality",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1 s2 s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures
cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
| union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3 | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.insert_nonmember_cardinality_lemma | val insert_nonmember_cardinality_lemma: Prims.unit -> Lemma (insert_nonmember_cardinality_fact) | val insert_nonmember_cardinality_lemma: Prims.unit -> Lemma (insert_nonmember_cardinality_fact) | let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 252,
"start_col": 0,
"start_line": 244
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.insert_nonmember_cardinality_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Negation",
"FStar.FiniteSet.Base.mem",
"Prims.op_Equality",
"Prims.int",
"FStar.FiniteSet.Base.cardinality",
"FStar.FiniteSet.Base.insert",
"Prims.op_Addition",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"FStar.FiniteSet.Base.nonrepeating_lists_with_same_elements_have_same_length",
"Prims.Cons",
"FStar.FiniteSet.Base.set_as_list",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"Prims.l_True",
"FStar.FiniteSet.Base.insert_nonmember_cardinality_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact) =
| introduce forall (a: eqtype) (s: set a) (x: a) . not (mem x s) ==>
cardinality (insert x s) = cardinality s + 1
with introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s))
(set_as_list (insert x s))) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.intersection_idempotent_left_lemma | val intersection_idempotent_left_lemma: Prims.unit -> Lemma (intersection_idempotent_left_fact) | val intersection_idempotent_left_lemma: Prims.unit -> Lemma (intersection_idempotent_left_fact) | let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2)) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 79,
"end_line": 298,
"start_col": 0,
"start_line": 295
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.intersection_idempotent_left_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.eq2",
"FStar.FiniteSet.Base.intersection",
"Prims._assert",
"FStar.FunctionalExtensionality.feq",
"Prims.bool",
"Prims.squash",
"Prims.l_True",
"FStar.FiniteSet.Base.intersection_idempotent_left_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let intersection_idempotent_left_lemma () : Lemma (intersection_idempotent_left_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . intersection s1 (intersection s1 s2) ==
intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.union_of_disjoint_lemma | val union_of_disjoint_lemma: Prims.unit -> Lemma (union_of_disjoint_fact) | val union_of_disjoint_lemma: Prims.unit -> Lemma (union_of_disjoint_fact) | let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 274,
"start_col": 0,
"start_line": 266
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.union_of_disjoint_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_imp",
"FStar.FiniteSet.Base.disjoint",
"Prims.l_and",
"Prims.eq2",
"FStar.FiniteSet.Base.difference",
"FStar.FiniteSet.Base.union",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"Prims._assert",
"FStar.FunctionalExtensionality.feq",
"Prims.bool",
"Prims.l_True",
"FStar.FiniteSet.Base.union_of_disjoint_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let union_of_disjoint_lemma () : Lemma (union_of_disjoint_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . disjoint s1 s2 ==>
difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\
difference (union s1 s2) s2 == s1
with _. (assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.union_of_disjoint_nonrepeating_lists_length_lemma | val union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1 xs2 xs3: list a)
: Lemma
(requires
list_nonrepeating xs1 /\ list_nonrepeating xs2 /\ list_nonrepeating xs3 /\
(forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2)) /\
(forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) | val union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1 xs2 xs3: list a)
: Lemma
(requires
list_nonrepeating xs1 /\ list_nonrepeating xs2 /\ list_nonrepeating xs3 /\
(forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2)) /\
(forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) | let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 111,
"end_line": 309,
"start_col": 0,
"start_line": 300
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | xs1: Prims.list a -> xs2: Prims.list a -> xs3: Prims.list a
-> FStar.Pervasives.Lemma
(requires
FStar.FiniteSet.Base.list_nonrepeating xs1 /\ FStar.FiniteSet.Base.list_nonrepeating xs2 /\
FStar.FiniteSet.Base.list_nonrepeating xs3 /\
(forall (x: a). ~(FStar.List.Tot.Base.mem x xs1 /\ FStar.List.Tot.Base.mem x xs2)) /\
(forall (x: a).
FStar.List.Tot.Base.mem x xs3 <==>
FStar.List.Tot.Base.mem x xs1 \/ FStar.List.Tot.Base.mem x xs2))
(ensures
FStar.List.Tot.Base.length xs3 =
FStar.List.Tot.Base.length xs1 + FStar.List.Tot.Base.length xs2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"FStar.FiniteSet.Base.nonrepeating_lists_with_same_elements_have_same_length",
"FStar.FiniteSet.Base.union_of_disjoint_nonrepeating_lists_length_lemma",
"FStar.FiniteSet.Base.remove_from_nonrepeating_list",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"FStar.FiniteSet.Base.list_nonrepeating",
"Prims.l_Forall",
"Prims.l_not",
"FStar.List.Tot.Base.mem",
"Prims.l_iff",
"Prims.l_or",
"Prims.squash",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1 xs2 xs3: list a)
: Lemma
(requires
list_nonrepeating xs1 /\ list_nonrepeating xs2 /\ list_nonrepeating xs3 /\
(forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2)) /\
(forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
| match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl ->
union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3) | false |
Steel.ST.GhostReference.fst | Steel.ST.GhostReference.share_gen | val share_gen
(#t: Type)
(#opened: _)
(#p: perm)
(#v: t)
(r: ref t)
(p1 p2: perm)
: STGhost unit opened
(pts_to r p v)
(fun _ -> pts_to r p1 v `star` pts_to r p2 v)
(p == p1 `sum_perm` p2)
(fun _ -> True) | val share_gen
(#t: Type)
(#opened: _)
(#p: perm)
(#v: t)
(r: ref t)
(p1 p2: perm)
: STGhost unit opened
(pts_to r p v)
(fun _ -> pts_to r p1 v `star` pts_to r p2 v)
(p == p1 `sum_perm` p2)
(fun _ -> True) | let share_gen
#_ #_ #_ #v r p1 p2
= coerce_ghost (fun _ -> R.ghost_share_gen_pt #_ #_ #_ #v r p1 p2) | {
"file_name": "lib/steel/Steel.ST.GhostReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 66,
"end_line": 84,
"start_col": 0,
"start_line": 82
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.GhostReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.Reference
[@@ erasable]
let ref (a:Type u#0)
: Type u#0
= R.ghost_ref a
let dummy_ref a = R.dummy_ghost_ref a
let pts_to (#a:_)
(r:ref a)
(p:perm)
([@@@smt_fallback] v:a)
: vprop
= R.ghost_pts_to r p v
let pts_to_injective_eq (#a:_)
(#u:_)
(#p #q:_)
(#v0 #v1:a)
(r:ref a)
: STGhost unit u
(pts_to r p v0 `star` pts_to r q v1)
(fun _ -> pts_to r p v0 `star` pts_to r q v0)
(requires True)
(ensures fun _ -> v0 == v1)
= coerce_ghost
(fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1))
let pts_to_perm r = coerce_ghost (fun _ -> R.ghost_pts_to_perm r)
let alloc (#a:Type)
(#u:_)
(x:erased a)
: STGhostT (ref a) u
emp
(fun r -> pts_to r full_perm x)
= coerce_ghost (fun _ -> R.ghost_alloc_pt x)
let read (#a:Type)
(#u:_)
(#p:perm)
(#v:erased a)
(r:ref a)
: STGhost (erased a) u
(pts_to r p v)
(fun x -> pts_to r p x)
(requires True)
(ensures fun x -> x == v)
= let y = coerce_ghost (fun _ -> R.ghost_read_pt r) in
y
let write (#a:Type)
(#u:_)
(#v:erased a)
(r:ref a)
(x:erased a)
: STGhostT unit u
(pts_to r full_perm v)
(fun _ -> pts_to r full_perm x)
= coerce_ghost (fun _ -> R.ghost_write_pt r x) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.Reference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GhostReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: Steel.ST.GhostReference.ref t ->
p1: Steel.FractionalPermission.perm ->
p2: Steel.FractionalPermission.perm
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.ST.GhostReference.ref",
"Steel.ST.Coercions.coerce_ghost",
"Prims.unit",
"Steel.Reference.ghost_pts_to",
"FStar.Ghost.reveal",
"FStar.Ghost.hide",
"Steel.Effect.Common.star",
"Steel.Effect.Common.vprop",
"Prims.eq2",
"Steel.FractionalPermission.sum_perm",
"Prims.l_True",
"Steel.Reference.ghost_share_gen_pt"
] | [] | false | true | false | false | false | let share_gen #_ #_ #_ #v r p1 p2 =
| coerce_ghost (fun _ -> R.ghost_share_gen_pt #_ #_ #_ #v r p1 p2) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.subset_lemma | val subset_lemma: Prims.unit -> Lemma (subset_fact) | val subset_lemma: Prims.unit -> Lemma (subset_fact) | let subset_lemma ()
: Lemma (subset_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)
with subset_helper a s1 s2 | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 381,
"start_col": 0,
"start_line": 378
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2
let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2
let subset_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) =
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _.
introduce forall x. s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.subset_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_iff",
"FStar.FiniteSet.Base.subset",
"Prims.l_imp",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"FStar.FiniteSet.Base.subset_helper",
"Prims.squash",
"Prims.l_True",
"FStar.FiniteSet.Base.subset_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let subset_lemma () : Lemma (subset_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . subset s1 s2 <==>
(forall o. {:pattern mem o s1\/mem o s2} mem o s1 ==> mem o s2)
with subset_helper a s1 s2 | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.subset_helper | val subset_helper (a: eqtype) (s1 s2: set a)
: Lemma (subset s1 s2 <==> (forall o. {:pattern mem o s1\/mem o s2} mem o s1 ==> mem o s2)) | val subset_helper (a: eqtype) (s1 s2: set a)
: Lemma (subset s1 s2 <==> (forall o. {:pattern mem o s1\/mem o s2} mem o s1 ==> mem o s2)) | let subset_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) =
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _.
introduce forall x. s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 376,
"start_col": 0,
"start_line": 371
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2
let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.eqtype -> s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a
-> FStar.Pervasives.Lemma
(ensures
FStar.FiniteSet.Base.subset s1 s2 <==>
(forall (o: a). {:pattern FStar.FiniteSet.Base.mem o s1\/FStar.FiniteSet.Base.mem o s2}
FStar.FiniteSet.Base.mem o s1 ==> FStar.FiniteSet.Base.mem o s2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.FiniteSet.Base.set",
"FStar.Classical.Sugar.implies_intro",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"Prims.squash",
"FStar.FiniteSet.Base.subset",
"FStar.Classical.Sugar.forall_intro",
"Prims.op_Equality",
"Prims.bool",
"Prims._assert",
"Prims.unit",
"Prims.l_True",
"Prims.l_iff",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let subset_helper (a: eqtype) (s1 s2: set a)
: Lemma (subset s1 s2 <==> (forall o. {:pattern mem o s1\/mem o s2} mem o s1 ==> mem o s2)) =
| introduce (forall o. {:pattern mem o s1\/mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _. introduce forall x . s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.intersection_idempotent_right_lemma | val intersection_idempotent_right_lemma: Prims.unit -> Lemma (intersection_idempotent_right_fact) | val intersection_idempotent_right_lemma: Prims.unit -> Lemma (intersection_idempotent_right_fact) | let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2)) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 79,
"end_line": 293,
"start_col": 0,
"start_line": 290
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.intersection_idempotent_right_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.eq2",
"FStar.FiniteSet.Base.intersection",
"Prims._assert",
"FStar.FunctionalExtensionality.feq",
"Prims.bool",
"Prims.squash",
"Prims.l_True",
"FStar.FiniteSet.Base.intersection_idempotent_right_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let intersection_idempotent_right_lemma () : Lemma (intersection_idempotent_right_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . intersection (intersection s1 s2) s2 ==
intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.intersection_cardinality_lemma | val intersection_cardinality_lemma: Prims.unit -> Lemma (intersection_cardinality_fact) | val intersection_cardinality_lemma: Prims.unit -> Lemma (intersection_cardinality_fact) | let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2 | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 345,
"start_col": 0,
"start_line": 340
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.intersection_cardinality_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"FStar.FiniteSet.Base.cardinality",
"FStar.FiniteSet.Base.union",
"FStar.FiniteSet.Base.intersection",
"FStar.FiniteSet.Base.intersection_cardinality_helper",
"Prims.squash",
"Prims.l_True",
"FStar.FiniteSet.Base.intersection_cardinality_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let intersection_cardinality_lemma () : Lemma (intersection_cardinality_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . cardinality (union s1 s2) +
cardinality (intersection s1 s2) =
cardinality s1 + cardinality s2
with intersection_cardinality_helper a s1 s2 | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.difference_cardinality_lemma | val difference_cardinality_lemma: Prims.unit -> Lemma (difference_cardinality_fact) | val difference_cardinality_lemma: Prims.unit -> Lemma (difference_cardinality_fact) | let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2 | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 369,
"start_col": 0,
"start_line": 362
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.difference_cardinality_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Addition",
"FStar.FiniteSet.Base.cardinality",
"FStar.FiniteSet.Base.difference",
"FStar.FiniteSet.Base.intersection",
"FStar.FiniteSet.Base.union",
"Prims.op_Subtraction",
"FStar.FiniteSet.Base.difference_cardinality_helper",
"Prims.squash",
"Prims.l_True",
"FStar.FiniteSet.Base.difference_cardinality_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let difference_cardinality_lemma () : Lemma (difference_cardinality_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . cardinality (difference s1 s2) +
cardinality (difference s2 s1) +
cardinality (intersection s1 s2) =
cardinality (union s1 s2) /\
cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with difference_cardinality_helper a s1 s2 | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.disjoint_lemma | val disjoint_lemma: Prims.unit -> Lemma (disjoint_fact) | val disjoint_lemma: Prims.unit -> Lemma (disjoint_fact) | let disjoint_lemma ()
: Lemma (disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
disjoint s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2))
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) ==> disjoint s1 s2
with _. (
introduce forall x. not (s1 x && s2 x)
with assert (not (mem x s1) \/ not (mem x s2))
)
) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 408,
"start_col": 0,
"start_line": 398
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2
let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2
let subset_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) =
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _.
introduce forall x. s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x)
let subset_lemma ()
: Lemma (subset_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)
with subset_helper a s1 s2
let equal_lemma ()
: Lemma (equal_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
equal s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2)
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2
with _.
introduce forall x. s1 x = true <==> s2 x = true
with assert (mem x s1 = s1 x /\ mem x s2 = s2 x)
)
let equal_extensionality_lemma ()
: Lemma (equal_extensionality_fact) =
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.disjoint_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_iff",
"FStar.FiniteSet.Base.disjoint",
"Prims.l_or",
"Prims.b2t",
"Prims.op_Negation",
"FStar.FiniteSet.Base.mem",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"Prims.op_AmpAmp",
"Prims._assert",
"Prims.l_True",
"FStar.FiniteSet.Base.disjoint_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let disjoint_lemma () : Lemma (disjoint_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . disjoint s1 s2 <==>
(forall o. {:pattern mem o s1\/mem o s2} not (mem o s1) \/ not (mem o s2))
with (introduce (forall o. {:pattern mem o s1\/mem o s2} not (mem o s1) \/ not (mem o s2)) ==> disjoint
s1
s2
with _. (introduce forall x . not (s1 x && s2 x)
with assert (not (mem x s1) \/ not (mem x s2)))) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.insert_remove_lemma | val insert_remove_lemma: Prims.unit -> Lemma (insert_remove_fact) | val insert_remove_lemma: Prims.unit -> Lemma (insert_remove_fact) | let insert_remove_lemma ()
: Lemma (insert_remove_fact) =
introduce forall (a: eqtype) (x: a) (s: set a). mem x s = true ==> insert x (remove x s) == s
with
introduce mem x s = true ==> insert x (remove x s) == s
with _. insert_remove_helper a x s | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 420,
"start_col": 0,
"start_line": 415
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2
let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2
let subset_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) =
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _.
introduce forall x. s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x)
let subset_lemma ()
: Lemma (subset_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)
with subset_helper a s1 s2
let equal_lemma ()
: Lemma (equal_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
equal s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2)
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2
with _.
introduce forall x. s1 x = true <==> s2 x = true
with assert (mem x s1 = s1 x /\ mem x s2 = s2 x)
)
let equal_extensionality_lemma ()
: Lemma (equal_extensionality_fact) =
()
let disjoint_lemma ()
: Lemma (disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
disjoint s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2))
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) ==> disjoint s1 s2
with _. (
introduce forall x. not (s1 x && s2 x)
with assert (not (mem x s1) \/ not (mem x s2))
)
)
let insert_remove_helper (a: eqtype) (x: a) (s: set a)
: Lemma (requires mem x s)
(ensures insert x (remove x s) == s) =
assert (feq s (insert x (remove x s))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.insert_remove_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"FStar.FiniteSet.Base.mem",
"Prims.eq2",
"FStar.FiniteSet.Base.insert",
"FStar.FiniteSet.Base.remove",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"FStar.FiniteSet.Base.insert_remove_helper",
"Prims.l_True",
"FStar.FiniteSet.Base.insert_remove_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let insert_remove_lemma () : Lemma (insert_remove_fact) =
| introduce forall (a: eqtype) (x: a) (s: set a) . mem x s = true ==> insert x (remove x s) == s
with introduce mem x s = true ==> insert x (remove x s) == s
with _. insert_remove_helper a x s | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.all_finite_set_facts_lemma | val all_finite_set_facts_lemma : unit -> Lemma (all_finite_set_facts) | val all_finite_set_facts_lemma : unit -> Lemma (all_finite_set_facts) | let all_finite_set_facts_lemma () : Lemma (all_finite_set_facts) =
empty_set_contains_no_elements_lemma ();
length_zero_lemma ();
singleton_contains_argument_lemma ();
singleton_contains_lemma ();
singleton_cardinality_lemma ();
insert_lemma ();
insert_contains_argument_lemma ();
insert_contains_lemma ();
insert_member_cardinality_lemma ();
insert_nonmember_cardinality_lemma ();
union_contains_lemma ();
union_contains_element_from_first_argument_lemma ();
union_contains_element_from_second_argument_lemma ();
union_of_disjoint_lemma ();
intersection_contains_lemma ();
union_idempotent_right_lemma ();
union_idempotent_left_lemma ();
intersection_idempotent_right_lemma ();
intersection_idempotent_left_lemma ();
intersection_cardinality_lemma ();
difference_contains_lemma ();
difference_doesnt_include_lemma ();
difference_cardinality_lemma ();
subset_lemma ();
equal_lemma ();
equal_extensionality_lemma ();
disjoint_lemma ();
insert_remove_lemma ();
remove_insert_lemma ();
set_as_list_cardinality_lemma () | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 468,
"start_col": 0,
"start_line": 438
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2
let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2
let subset_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) =
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _.
introduce forall x. s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x)
let subset_lemma ()
: Lemma (subset_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)
with subset_helper a s1 s2
let equal_lemma ()
: Lemma (equal_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
equal s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2)
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2
with _.
introduce forall x. s1 x = true <==> s2 x = true
with assert (mem x s1 = s1 x /\ mem x s2 = s2 x)
)
let equal_extensionality_lemma ()
: Lemma (equal_extensionality_fact) =
()
let disjoint_lemma ()
: Lemma (disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
disjoint s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2))
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) ==> disjoint s1 s2
with _. (
introduce forall x. not (s1 x && s2 x)
with assert (not (mem x s1) \/ not (mem x s2))
)
)
let insert_remove_helper (a: eqtype) (x: a) (s: set a)
: Lemma (requires mem x s)
(ensures insert x (remove x s) == s) =
assert (feq s (insert x (remove x s)))
let insert_remove_lemma ()
: Lemma (insert_remove_fact) =
introduce forall (a: eqtype) (x: a) (s: set a). mem x s = true ==> insert x (remove x s) == s
with
introduce mem x s = true ==> insert x (remove x s) == s
with _. insert_remove_helper a x s
let remove_insert_helper (a: eqtype) (x: a) (s: set a)
: Lemma (requires mem x s = false)
(ensures remove x (insert x s) == s) =
assert (feq s (remove x (insert x s)))
let remove_insert_lemma ()
: Lemma (remove_insert_fact) =
introduce forall (a: eqtype) (x: a) (s: set a). mem x s = false ==> remove x (insert x s) == s
with introduce mem x s = false ==> remove x (insert x s) == s
with _. remove_insert_helper a x s
let set_as_list_cardinality_lemma ()
: Lemma (set_as_list_cardinality_fact) =
introduce forall (a: eqtype) (s: set a). FLT.length (set_as_list s) = cardinality s
with reveal_opaque (`%cardinality) (cardinality #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.all_finite_set_facts) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.FiniteSet.Base.set_as_list_cardinality_lemma",
"FStar.FiniteSet.Base.remove_insert_lemma",
"FStar.FiniteSet.Base.insert_remove_lemma",
"FStar.FiniteSet.Base.disjoint_lemma",
"FStar.FiniteSet.Base.equal_extensionality_lemma",
"FStar.FiniteSet.Base.equal_lemma",
"FStar.FiniteSet.Base.subset_lemma",
"FStar.FiniteSet.Base.difference_cardinality_lemma",
"FStar.FiniteSet.Base.difference_doesnt_include_lemma",
"FStar.FiniteSet.Base.difference_contains_lemma",
"FStar.FiniteSet.Base.intersection_cardinality_lemma",
"FStar.FiniteSet.Base.intersection_idempotent_left_lemma",
"FStar.FiniteSet.Base.intersection_idempotent_right_lemma",
"FStar.FiniteSet.Base.union_idempotent_left_lemma",
"FStar.FiniteSet.Base.union_idempotent_right_lemma",
"FStar.FiniteSet.Base.intersection_contains_lemma",
"FStar.FiniteSet.Base.union_of_disjoint_lemma",
"FStar.FiniteSet.Base.union_contains_element_from_second_argument_lemma",
"FStar.FiniteSet.Base.union_contains_element_from_first_argument_lemma",
"FStar.FiniteSet.Base.union_contains_lemma",
"FStar.FiniteSet.Base.insert_nonmember_cardinality_lemma",
"FStar.FiniteSet.Base.insert_member_cardinality_lemma",
"FStar.FiniteSet.Base.insert_contains_lemma",
"FStar.FiniteSet.Base.insert_contains_argument_lemma",
"FStar.FiniteSet.Base.insert_lemma",
"FStar.FiniteSet.Base.singleton_cardinality_lemma",
"FStar.FiniteSet.Base.singleton_contains_lemma",
"FStar.FiniteSet.Base.singleton_contains_argument_lemma",
"FStar.FiniteSet.Base.length_zero_lemma",
"FStar.FiniteSet.Base.empty_set_contains_no_elements_lemma",
"Prims.l_True",
"Prims.squash",
"FStar.FiniteSet.Base.all_finite_set_facts",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let all_finite_set_facts_lemma () : Lemma (all_finite_set_facts) =
| empty_set_contains_no_elements_lemma ();
length_zero_lemma ();
singleton_contains_argument_lemma ();
singleton_contains_lemma ();
singleton_cardinality_lemma ();
insert_lemma ();
insert_contains_argument_lemma ();
insert_contains_lemma ();
insert_member_cardinality_lemma ();
insert_nonmember_cardinality_lemma ();
union_contains_lemma ();
union_contains_element_from_first_argument_lemma ();
union_contains_element_from_second_argument_lemma ();
union_of_disjoint_lemma ();
intersection_contains_lemma ();
union_idempotent_right_lemma ();
union_idempotent_left_lemma ();
intersection_idempotent_right_lemma ();
intersection_idempotent_left_lemma ();
intersection_cardinality_lemma ();
difference_contains_lemma ();
difference_doesnt_include_lemma ();
difference_cardinality_lemma ();
subset_lemma ();
equal_lemma ();
equal_extensionality_lemma ();
disjoint_lemma ();
insert_remove_lemma ();
remove_insert_lemma ();
set_as_list_cardinality_lemma () | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.set_as_list_cardinality_lemma | val set_as_list_cardinality_lemma: Prims.unit -> Lemma (set_as_list_cardinality_fact) | val set_as_list_cardinality_lemma: Prims.unit -> Lemma (set_as_list_cardinality_fact) | let set_as_list_cardinality_lemma ()
: Lemma (set_as_list_cardinality_fact) =
introduce forall (a: eqtype) (s: set a). FLT.length (set_as_list s) = cardinality s
with reveal_opaque (`%cardinality) (cardinality #a) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 436,
"start_col": 0,
"start_line": 433
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2
let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2
let subset_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) =
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _.
introduce forall x. s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x)
let subset_lemma ()
: Lemma (subset_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)
with subset_helper a s1 s2
let equal_lemma ()
: Lemma (equal_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
equal s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2)
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2
with _.
introduce forall x. s1 x = true <==> s2 x = true
with assert (mem x s1 = s1 x /\ mem x s2 = s2 x)
)
let equal_extensionality_lemma ()
: Lemma (equal_extensionality_fact) =
()
let disjoint_lemma ()
: Lemma (disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
disjoint s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2))
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) ==> disjoint s1 s2
with _. (
introduce forall x. not (s1 x && s2 x)
with assert (not (mem x s1) \/ not (mem x s2))
)
)
let insert_remove_helper (a: eqtype) (x: a) (s: set a)
: Lemma (requires mem x s)
(ensures insert x (remove x s) == s) =
assert (feq s (insert x (remove x s)))
let insert_remove_lemma ()
: Lemma (insert_remove_fact) =
introduce forall (a: eqtype) (x: a) (s: set a). mem x s = true ==> insert x (remove x s) == s
with
introduce mem x s = true ==> insert x (remove x s) == s
with _. insert_remove_helper a x s
let remove_insert_helper (a: eqtype) (x: a) (s: set a)
: Lemma (requires mem x s = false)
(ensures remove x (insert x s) == s) =
assert (feq s (remove x (insert x s)))
let remove_insert_lemma ()
: Lemma (remove_insert_fact) =
introduce forall (a: eqtype) (x: a) (s: set a). mem x s = false ==> remove x (insert x s) == s
with introduce mem x s = false ==> remove x (insert x s) == s
with _. remove_insert_helper a x s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.set_as_list_cardinality_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.FiniteSet.Base.set_as_list",
"FStar.FiniteSet.Base.cardinality",
"FStar.Pervasives.reveal_opaque",
"Prims.squash",
"Prims.l_True",
"FStar.FiniteSet.Base.set_as_list_cardinality_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let set_as_list_cardinality_lemma () : Lemma (set_as_list_cardinality_fact) =
| introduce forall (a: eqtype) (s: set a) . FLT.length (set_as_list s) = cardinality s
with reveal_opaque (`%cardinality) (cardinality #a) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.equal_lemma | val equal_lemma: Prims.unit -> Lemma (equal_fact) | val equal_lemma: Prims.unit -> Lemma (equal_fact) | let equal_lemma ()
: Lemma (equal_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
equal s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2)
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2
with _.
introduce forall x. s1 x = true <==> s2 x = true
with assert (mem x s1 = s1 x /\ mem x s2 = s2 x)
) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 392,
"start_col": 0,
"start_line": 383
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2
let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2
let subset_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) =
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _.
introduce forall x. s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x)
let subset_lemma ()
: Lemma (subset_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)
with subset_helper a s1 s2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.equal_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_iff",
"FStar.FiniteSet.Base.equal",
"Prims.b2t",
"FStar.FiniteSet.Base.mem",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"Prims.op_Equality",
"Prims.bool",
"Prims._assert",
"Prims.l_and",
"Prims.l_True",
"FStar.FiniteSet.Base.equal_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let equal_lemma () : Lemma (equal_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . equal s1 s2 <==>
(forall o. {:pattern mem o s1\/mem o s2} mem o s1 <==> mem o s2)
with (introduce (forall o. {:pattern mem o s1\/mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2
with _. introduce forall x . s1 x = true <==> s2 x = true
with assert (mem x s1 = s1 x /\ mem x s2 = s2 x)) | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.remove_insert_lemma | val remove_insert_lemma: Prims.unit -> Lemma (remove_insert_fact) | val remove_insert_lemma: Prims.unit -> Lemma (remove_insert_fact) | let remove_insert_lemma ()
: Lemma (remove_insert_fact) =
introduce forall (a: eqtype) (x: a) (s: set a). mem x s = false ==> remove x (insert x s) == s
with introduce mem x s = false ==> remove x (insert x s) == s
with _. remove_insert_helper a x s | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 431,
"start_col": 0,
"start_line": 427
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
()
let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2))
let union_idempotent_left_lemma ()
: Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2
with assert (feq (union s1 (union s1 s2)) (union s1 s2))
let intersection_idempotent_right_lemma ()
: Lemma (intersection_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2
with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2))
let intersection_idempotent_left_lemma ()
: Lemma (intersection_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2
with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2))
let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a)
: Lemma (requires list_nonrepeating xs1
/\ list_nonrepeating xs2
/\ list_nonrepeating xs3
/\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2))
/\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2))
(ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) =
match xs1 with
| [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3
| hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3)
let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (requires disjoint s1 s2)
(ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) =
reveal_opaque (`%cardinality) (cardinality #a);
union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2))
let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a)
: Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3)
(ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) =
union_of_disjoint_sets_cardinality_lemma s1 s2;
union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2);
assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a)
: Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) =
cardinality_matches_difference_plus_intersection_lemma s1 s2;
cardinality_matches_difference_plus_intersection_lemma s2 s1;
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
assert (feq (intersection s1 s2) (intersection s2 s1))
let intersection_cardinality_lemma ()
: Lemma (intersection_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2
with
intersection_cardinality_helper a s1 s2
let difference_contains_lemma ()
: Lemma (difference_contains_fact) =
()
let difference_doesnt_include_lemma ()
: Lemma (difference_doesnt_include_fact) =
()
let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) =
union_is_differences_and_intersection s1 s2;
union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1);
cardinality_matches_difference_plus_intersection_lemma s1 s2
let difference_cardinality_lemma ()
: Lemma (difference_cardinality_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
cardinality (difference s1 s2) + cardinality (difference s2 s1) +
cardinality (intersection s1 s2) = cardinality (union s1 s2)
/\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)
with
difference_cardinality_helper a s1 s2
let subset_helper (a: eqtype) (s1: set a) (s2: set a)
: Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) =
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2
with _.
introduce forall x. s1 x = true ==> s2 x = true
with assert (mem x s1 = s1 x)
let subset_lemma ()
: Lemma (subset_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)
with subset_helper a s1 s2
let equal_lemma ()
: Lemma (equal_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
equal s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2)
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2
with _.
introduce forall x. s1 x = true <==> s2 x = true
with assert (mem x s1 = s1 x /\ mem x s2 = s2 x)
)
let equal_extensionality_lemma ()
: Lemma (equal_extensionality_fact) =
()
let disjoint_lemma ()
: Lemma (disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a).
disjoint s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2))
with (
introduce (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) ==> disjoint s1 s2
with _. (
introduce forall x. not (s1 x && s2 x)
with assert (not (mem x s1) \/ not (mem x s2))
)
)
let insert_remove_helper (a: eqtype) (x: a) (s: set a)
: Lemma (requires mem x s)
(ensures insert x (remove x s) == s) =
assert (feq s (insert x (remove x s)))
let insert_remove_lemma ()
: Lemma (insert_remove_fact) =
introduce forall (a: eqtype) (x: a) (s: set a). mem x s = true ==> insert x (remove x s) == s
with
introduce mem x s = true ==> insert x (remove x s) == s
with _. insert_remove_helper a x s
let remove_insert_helper (a: eqtype) (x: a) (s: set a)
: Lemma (requires mem x s = false)
(ensures remove x (insert x s) == s) =
assert (feq s (remove x (insert x s))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.remove_insert_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"FStar.FiniteSet.Base.mem",
"Prims.eq2",
"FStar.FiniteSet.Base.remove",
"FStar.FiniteSet.Base.insert",
"FStar.Classical.Sugar.implies_intro",
"Prims.squash",
"FStar.FiniteSet.Base.remove_insert_helper",
"Prims.l_True",
"FStar.FiniteSet.Base.remove_insert_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let remove_insert_lemma () : Lemma (remove_insert_fact) =
| introduce forall (a: eqtype) (x: a) (s: set a) . mem x s = false ==> remove x (insert x s) == s
with introduce mem x s = false ==> remove x (insert x s) == s
with _. remove_insert_helper a x s | false |
FStar.FiniteSet.Base.fst | FStar.FiniteSet.Base.union_idempotent_right_lemma | val union_idempotent_right_lemma: Prims.unit -> Lemma (union_idempotent_right_fact) | val union_idempotent_right_lemma: Prims.unit -> Lemma (union_idempotent_right_fact) | let union_idempotent_right_lemma ()
: Lemma (union_idempotent_right_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2)) | {
"file_name": "ulib/FStar.FiniteSet.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 283,
"start_col": 0,
"start_line": 280
} | (*
Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers,
Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to
the Dafny Project
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.
Includes material from the Dafny project
(https://github.com/dafny-lang/dafny) which carries this license
information:
Created 9 February 2008 by Rustan Leino.
Converted to Boogie 2 on 28 June 2008.
Edited sequence axioms 20 October 2009 by Alex Summers.
Modified 2014 by Dan Rosen.
Copyright (c) 2008-2014, Microsoft.
Copyright by the contributors to the Dafny Project
SPDX-License-Identifier: MIT
*)
(**
This module declares a type and functions used for modeling
finite sets as they're modeled in Dafny.
@summary Type and functions for modeling finite sets
*)
module FStar.FiniteSet.Base
module FLT = FStar.List.Tot
open FStar.FunctionalExtensionality
let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop =
forall x. f x == x `FLT.mem` xs
// Finite sets
type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs}
/// We represent the Dafny function [] on sets with `mem`:
let mem (#a: eqtype) (x: a) (s: set a) : bool =
s x
/// We represent the Dafny function `Set#Card` with `cardinality`:
///
/// function Set#Card<T>(Set T): int;
let rec remove_repeats (#a: eqtype) (xs: list a)
: (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) =
match xs with
| [] -> []
| hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl'
let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) =
remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s))
[@"opaque_to_smt"]
let cardinality (#a: eqtype) (s: set a) : GTot nat =
FLT.length (set_as_list s)
let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a))
: Pure (set a)
(requires f `has_elements` xs)
(ensures fun _ -> True)
= Classical.exists_intro (fun xs -> f `has_elements` xs) xs;
f
/// We represent the Dafny function `Set#Empty` with `empty`:
let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) []
/// We represent the Dafny function `Set#UnionOne` with `insert`:
///
/// function Set#UnionOne<T>(Set T, T): Set T;
let insert (#a: eqtype) (x: a) (s: set a): set a =
intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s)
/// We represent the Dafny function `Set#Singleton` with `singleton`:
///
/// function Set#Singleton<T>(T): Set T;
let singleton (#a: eqtype) (x: a) : set a =
insert x emptyset
/// We represent the Dafny function `Set#Union` with `union`:
///
/// function Set#Union<T>(Set T, Set T): Set T;
let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) =
match xs with
| [] -> ys
| hd :: tl -> hd :: union_lists tl ys
let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) =
intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Intersection` with `intersection`:
///
/// function Set#Intersection<T>(Set T, Set T): Set T;
let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs'
let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Difference` with `difference`:
///
/// function Set#Difference<T>(Set T, Set T): Set T;
let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a)
: (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) =
match xs with
| [] -> []
| hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs'
let difference (#a: eqtype) (s1: set a) (s2: set a) : set a =
intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2))
/// We represent the Dafny function `Set#Subset` with `subset`:
///
/// function Set#Subset<T>(Set T, Set T): bool;
let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. (s1 x = true) ==> (s2 x = true)
/// We represent the Dafny function `Set#Equal` with `equal`:
///
/// function Set#Equal<T>(Set T, Set T): bool;
let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
feq s1 s2
/// We represent the Dafny function `Set#Disjoint` with `disjoint`:
///
/// function Set#Disjoint<T>(Set T, Set T): bool;
let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 =
forall x. not (s1 x && s2 x)
/// We represent the Dafny choice operator by `choose`:
///
/// var x: T :| x in s;
let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) =
Cons?.hd (set_as_list s)
/// We now prove each of the facts that comprise `all_finite_set_facts`.
/// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that
/// requires a helper lemma, which we call `xxx_helper`.
let empty_set_contains_no_elements_lemma ()
: Lemma (empty_set_contains_no_elements_fact) =
()
let length_zero_lemma ()
: Lemma (length_zero_fact) =
introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s))
with (
reveal_opaque (`%cardinality) (cardinality #a);
introduce cardinality s = 0 ==> s == emptyset
with _. assert (feq s emptyset);
introduce s == emptyset ==> cardinality s = 0
with _. assert (set_as_list s == []);
introduce cardinality s <> 0 ==> _
with _. introduce exists x. mem x s
with (Cons?.hd (set_as_list s))
and ())
let singleton_contains_argument_lemma ()
: Lemma (singleton_contains_argument_fact) =
()
let singleton_contains_lemma ()
: Lemma (singleton_contains_fact) =
()
let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a)
: Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r))
(ensures remove_repeats xs == [r]) =
match xs with
| [x] -> ()
| hd :: tl ->
assert (Cons?.hd tl = r);
singleton_cardinality_helper r tl
let singleton_cardinality_lemma ()
: Lemma (singleton_cardinality_fact) =
introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1
with (
reveal_opaque (`%cardinality) (cardinality #a);
singleton_cardinality_helper r (set_as_list (singleton r))
)
let insert_lemma ()
: Lemma (insert_fact) =
()
let insert_contains_argument_lemma ()
: Lemma (insert_contains_argument_fact) =
()
let insert_contains_lemma ()
: Lemma (insert_contains_fact) =
()
let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs})
: (xs': list a{ list_nonrepeating xs'
/\ FLT.length xs' = FLT.length xs - 1
/\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) =
match xs with
| hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl)
let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a)
: Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2))
(ensures FLT.length s1 = FLT.length s2) =
match s1 with
| [] -> ()
| hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2)
let insert_member_cardinality_lemma ()
: Lemma (insert_member_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s
with
introduce mem x s ==> cardinality (insert x s) = cardinality s
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s))
)
let insert_nonmember_cardinality_lemma ()
: Lemma (insert_nonmember_cardinality_fact) =
introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with
introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1
with _. (
reveal_opaque (`%cardinality) (cardinality #a);
nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s))
)
let union_contains_lemma ()
: Lemma (union_contains_fact) =
()
let union_contains_element_from_first_argument_lemma ()
: Lemma (union_contains_element_from_first_argument_fact) =
()
let union_contains_element_from_second_argument_lemma ()
: Lemma (union_contains_element_from_second_argument_fact) =
()
let union_of_disjoint_lemma ()
: Lemma (union_of_disjoint_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with
introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1
with _. (
assert (feq (difference (union s1 s2) s1) s2);
assert (feq (difference (union s1 s2) s2) s1)
)
let intersection_contains_lemma ()
: Lemma (intersection_contains_fact) =
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.FiniteSet.Base.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "FLT"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FiniteSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.union_idempotent_right_fact) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.Sugar.forall_intro",
"Prims.eqtype",
"Prims.l_Forall",
"FStar.FiniteSet.Base.set",
"Prims.eq2",
"FStar.FiniteSet.Base.union",
"Prims._assert",
"FStar.FunctionalExtensionality.feq",
"Prims.bool",
"Prims.squash",
"Prims.l_True",
"FStar.FiniteSet.Base.union_idempotent_right_fact",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let union_idempotent_right_lemma () : Lemma (union_idempotent_right_fact) =
| introduce forall (a: eqtype) (s1: set a) (s2: set a) . union (union s1 s2) s2 == union s1 s2
with assert (feq (union (union s1 s2) s2) (union s1 s2)) | false |
Vale.AES.GCTR.fst | Vale.AES.GCTR.gctr_partial_opaque_init | val gctr_partial_opaque_init (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma
(requires is_aes_key_LE alg key)
(ensures gctr_partial alg 0 plain cipher key icb) | val gctr_partial_opaque_init (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma
(requires is_aes_key_LE alg key)
(ensures gctr_partial alg 0 plain cipher key icb) | let gctr_partial_opaque_init alg plain cipher key icb =
gctr_partial_reveal ();
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 54,
"start_col": 0,
"start_line": 52
} | module Vale.AES.GCTR
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open Vale.AES.GCM_helpers
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
#set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0"
let lemma_counter_init x low64 low8 =
Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64;
Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff;
assert (low8 == low64 % 256);
lo64_reveal ();
assert_norm (pow2_norm 32 == pow2_32); // OBSERVE
assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE
assert (low64 % 256 == x.lo0 % 256);
()
let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) =
()
let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
gctr_encrypt_LE_reveal ();
let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in
let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in
assert (plain == empty);
assert (cipher == empty);
assert (length plain == 0);
assert (make_gctr_plain_LE plain == empty);
let num_extra = (length (make_gctr_plain_LE plain)) % 16 in
assert (num_extra == 0);
let plain_quads_LE = le_bytes_to_seq_quad32 plain in
let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in
assert (equal plain_quads_LE empty); // OBSERVE
assert (plain_quads_LE == empty);
assert (cipher_quads_LE == empty);
assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs
() | {
"checked_file": "/",
"dependencies": [
"Vale.Poly1305.Bitvectors.fsti.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCTR.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
plain: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 ->
icb: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key)
(ensures Vale.AES.GCTR.gctr_partial alg 0 plain cipher key icb) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"Vale.AES.GCTR.gctr_partial_reveal"
] | [] | true | false | true | false | false | let gctr_partial_opaque_init alg plain cipher key icb =
| gctr_partial_reveal ();
() | false |
Steel.ST.GhostReference.fst | Steel.ST.GhostReference.alloc | val alloc (#a:Type)
(#u:_)
(x:erased a)
: STGhostT (ref a) u
emp
(fun r -> pts_to r full_perm x) | val alloc (#a:Type)
(#u:_)
(x:erased a)
: STGhostT (ref a) u
emp
(fun r -> pts_to r full_perm x) | let alloc (#a:Type)
(#u:_)
(x:erased a)
: STGhostT (ref a) u
emp
(fun r -> pts_to r full_perm x)
= coerce_ghost (fun _ -> R.ghost_alloc_pt x) | {
"file_name": "lib/steel/Steel.ST.GhostReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 57,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.GhostReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.Reference
[@@ erasable]
let ref (a:Type u#0)
: Type u#0
= R.ghost_ref a
let dummy_ref a = R.dummy_ghost_ref a
let pts_to (#a:_)
(r:ref a)
(p:perm)
([@@@smt_fallback] v:a)
: vprop
= R.ghost_pts_to r p v
let pts_to_injective_eq (#a:_)
(#u:_)
(#p #q:_)
(#v0 #v1:a)
(r:ref a)
: STGhost unit u
(pts_to r p v0 `star` pts_to r q v1)
(fun _ -> pts_to r p v0 `star` pts_to r q v0)
(requires True)
(ensures fun _ -> v0 == v1)
= coerce_ghost
(fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1))
let pts_to_perm r = coerce_ghost (fun _ -> R.ghost_pts_to_perm r) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.Reference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GhostReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Ghost.erased a -> Steel.ST.Effect.Ghost.STGhostT (Steel.ST.GhostReference.ref a) | Steel.ST.Effect.Ghost.STGhostT | [] | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Steel.ST.Coercions.coerce_ghost",
"Steel.Reference.ghost_ref",
"Steel.Effect.Common.emp",
"Steel.Reference.ghost_pts_to",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Prims.unit",
"Steel.Reference.ghost_alloc_pt",
"Steel.ST.GhostReference.ref",
"Steel.ST.GhostReference.pts_to"
] | [] | false | true | false | false | false | let alloc (#a: Type) (#u: _) (x: erased a) : STGhostT (ref a) u emp (fun r -> pts_to r full_perm x) =
| coerce_ghost (fun _ -> R.ghost_alloc_pt x) | false |
Steel.ST.GhostReference.fst | Steel.ST.GhostReference.free | val free (#a:Type0)
(#u:_)
(#v:erased a)
(r:ref a)
: STGhostT unit u
(pts_to r full_perm v)
(fun _ -> emp) | val free (#a:Type0)
(#u:_)
(#v:erased a)
(r:ref a)
: STGhostT unit u
(pts_to r full_perm v)
(fun _ -> emp) | let free (#a:Type0)
(#u:_)
(#v:erased a)
(r:ref a)
: STGhostT unit u
(pts_to r full_perm v)
(fun _ -> emp)
= coerce_ghost (fun _ -> R.ghost_free_pt r) | {
"file_name": "lib/steel/Steel.ST.GhostReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 116,
"start_col": 0,
"start_line": 109
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.GhostReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.Reference
[@@ erasable]
let ref (a:Type u#0)
: Type u#0
= R.ghost_ref a
let dummy_ref a = R.dummy_ghost_ref a
let pts_to (#a:_)
(r:ref a)
(p:perm)
([@@@smt_fallback] v:a)
: vprop
= R.ghost_pts_to r p v
let pts_to_injective_eq (#a:_)
(#u:_)
(#p #q:_)
(#v0 #v1:a)
(r:ref a)
: STGhost unit u
(pts_to r p v0 `star` pts_to r q v1)
(fun _ -> pts_to r p v0 `star` pts_to r q v0)
(requires True)
(ensures fun _ -> v0 == v1)
= coerce_ghost
(fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1))
let pts_to_perm r = coerce_ghost (fun _ -> R.ghost_pts_to_perm r)
let alloc (#a:Type)
(#u:_)
(x:erased a)
: STGhostT (ref a) u
emp
(fun r -> pts_to r full_perm x)
= coerce_ghost (fun _ -> R.ghost_alloc_pt x)
let read (#a:Type)
(#u:_)
(#p:perm)
(#v:erased a)
(r:ref a)
: STGhost (erased a) u
(pts_to r p v)
(fun x -> pts_to r p x)
(requires True)
(ensures fun x -> x == v)
= let y = coerce_ghost (fun _ -> R.ghost_read_pt r) in
y
let write (#a:Type)
(#u:_)
(#v:erased a)
(r:ref a)
(x:erased a)
: STGhostT unit u
(pts_to r full_perm v)
(fun _ -> pts_to r full_perm x)
= coerce_ghost (fun _ -> R.ghost_write_pt r x)
let share_gen
#_ #_ #_ #v r p1 p2
= coerce_ghost (fun _ -> R.ghost_share_gen_pt #_ #_ #_ #v r p1 p2)
let share (#a:Type)
(#u:_)
(#p:perm)
(#x:erased a)
(r:ref a)
: STGhostT unit u
(pts_to r p x)
(fun _ -> pts_to r (half_perm p) x `star`
pts_to r (half_perm p) x)
= coerce_ghost (fun _ -> R.ghost_share_pt r)
let gather (#a:Type)
(#u:_)
(#p0 #p1:perm)
(#x0 #x1:erased a)
(r:ref a)
: STGhost unit u
(pts_to r p0 x0 `star` pts_to r p1 x1)
(fun _ -> pts_to r (sum_perm p0 p1) x0)
(requires True)
(ensures fun _ -> x0 == x1)
= coerce_ghost (fun _ -> R.ghost_gather_pt #a #u #p0 #p1 #x0 #x1 r) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.Reference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GhostReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.ST.GhostReference.ref a -> Steel.ST.Effect.Ghost.STGhostT Prims.unit | Steel.ST.Effect.Ghost.STGhostT | [] | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Steel.ST.GhostReference.ref",
"Steel.ST.Coercions.coerce_ghost",
"Prims.unit",
"Steel.Reference.ghost_pts_to",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.reveal",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Steel.Reference.ghost_free_pt",
"Steel.ST.GhostReference.pts_to"
] | [] | false | true | false | false | false | let free (#a: Type0) (#u: _) (#v: erased a) (r: ref a)
: STGhostT unit u (pts_to r full_perm v) (fun _ -> emp) =
| coerce_ghost (fun _ -> R.ghost_free_pt r) | false |
Vale.AES.GCTR.fst | Vale.AES.GCTR.gctr_encrypt_empty | val gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) : Lemma
(requires is_aes_key_LE alg key)
(ensures (
let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in
let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in
cipher = gctr_encrypt_LE icb_BE (make_gctr_plain_LE plain) alg key
)) | val gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) : Lemma
(requires is_aes_key_LE alg key)
(ensures (
let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in
let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in
cipher = gctr_encrypt_LE icb_BE (make_gctr_plain_LE plain) alg key
)) | let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
gctr_encrypt_LE_reveal ();
let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in
let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in
assert (plain == empty);
assert (cipher == empty);
assert (length plain == 0);
assert (make_gctr_plain_LE plain == empty);
let num_extra = (length (make_gctr_plain_LE plain)) % 16 in
assert (num_extra == 0);
let plain_quads_LE = le_bytes_to_seq_quad32 plain in
let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in
assert (equal plain_quads_LE empty); // OBSERVE
assert (plain_quads_LE == empty);
assert (cipher_quads_LE == empty);
assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 50,
"start_col": 0,
"start_line": 33
} | module Vale.AES.GCTR
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open Vale.AES.GCM_helpers
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
#set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0"
let lemma_counter_init x low64 low8 =
Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64;
Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff;
assert (low8 == low64 % 256);
lo64_reveal ();
assert_norm (pow2_norm 32 == pow2_32); // OBSERVE
assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE
assert (low64 % 256 == x.lo0 % 256);
()
let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) =
() | {
"checked_file": "/",
"dependencies": [
"Vale.Poly1305.Bitvectors.fsti.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCTR.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
icb_BE: Vale.Def.Types_s.quad32 ->
plain_LE: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
cipher_LE: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32
-> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key)
(ensures
(let plain = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes plain_LE) 0 0 in
let cipher =
FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes cipher_LE) 0 0
in
cipher =
Vale.AES.GCTR_s.gctr_encrypt_LE icb_BE (Vale.AES.GCTR.make_gctr_plain_LE plain) alg key)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"FStar.Seq.Base.empty",
"Prims.eq2",
"Vale.AES.GCTR_s.gctr_encrypt_recursive",
"Vale.Def.Types_s.le_bytes_to_seq_quad32",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Vale.AES.GCTR.make_gctr_plain_LE",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.slice",
"Vale.AES.GCTR_s.gctr_encrypt_LE_reveal",
"FStar.Pervasives.reveal_opaque",
"Prims.l_True"
] | [] | true | false | true | false | false | let gctr_encrypt_empty
(icb_BE: quad32)
(plain_LE cipher_LE: seq quad32)
(alg: algorithm)
(key: seq nat32)
=
| reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
gctr_encrypt_LE_reveal ();
let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in
let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in
assert (plain == empty);
assert (cipher == empty);
assert (length plain == 0);
assert (make_gctr_plain_LE plain == empty);
let num_extra = (length (make_gctr_plain_LE plain)) % 16 in
assert (num_extra == 0);
let plain_quads_LE = le_bytes_to_seq_quad32 plain in
let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in
assert (equal plain_quads_LE empty);
assert (plain_quads_LE == empty);
assert (cipher_quads_LE == empty);
assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty);
() | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.